Common linux commands and common linux commands

Source: Internet
Author: User

Common linux commands and common linux commands

1. Change the group to which the chgrp belongs:

For example, change the group of install. log to users.

   

chgrp users install.log

   

ls –l

View results: root users 68495 25 install. log

Owner Group

2. chown changes the owner

For example, change the owner of the install. log file to the Account "bin ".

   

chown    bin    install.log

ls –l

Result: bin users 68945 25 install. log

For example, change the owner and group of install. log to root.

   

chown     root:root    install.log

ls –l

Result: root 68495 25 install. log

3. Change permissions

There are two methods to set permissions. One is to use numbers and the other is to use symbols to set permissions.

· Use numbers to set permissions

There are nine basic permissions for linux Files: owner, group, and others. Each has its own read, write, and execute permissions, which are r: 4, w: 2, and x: 1 each identity must be accumulated

Example:

   

ls –a .bashrc

-rw-r—r--   1   root  root   385 jul   4 11:45  .bashrc

chmod  777 .bashrc

ls –a .bashrc

-rwxrwxrwx   1   root   root   385  jul 4  11:35  .bashrc

· Change the File Permission of the symbol type

U, g, and a represent user, group, and others respectively, and a represent all, that is, all identities. + indicates adding,-Indicates removing, and = indicates setting.

Example:

   

Chmod u = rwx, go = rx. bashrc

Note: The intermediate u = rwx and go = rx are connected together without any spaces.

Chmod a + w. bashrc

Chmod a-x. bashrc

4. Directory-related operations

Cd (Change directory)

Pwd (display the current directory)

   

[Root @ www ~] # Pwd [-P]

Option and parameter:-P: displays the actual path instead of the link path.

Example: simply display the current working directory:

[Root @ www ~] # Pwd/root <= show the directory ~

Example: display the actual working directory instead of the directory name of The Link file.

[Root @ www ~] # Cd/var/mail <= Note:/var/mail is a link file.

[Root @ www mail] # pwd/var/mail <= List the current working directory

[Root @ www mail] # pwd-P/var/spool/mail <= what's going on? Is there a lot of difference between-P ~

[Root @ www mail] # ls-ld/var/mail

Lrwxrwxrwx 1 root 10 Sep 4 :54/var/mail-> spool/mail

# Do you know why? Because/var/mail is a link file and linked to/var/spool/mail #, after the pwd-P option is added, data in the Link file is not displayed, the correct complete path is displayed!

Mkdir (create a new directory)

   

[Root @ www ~] # Mkdir [-mp] Directory Name

Options and parameters:

-M: permission of the configuration file! Directly configure it. You do not need to check the face of the default permission (umask ~

-P: helps you directly create the desired directory (including the upper-level directory!

Example: Go to/tmp and try to create several new directories:

[Root @ www ~] # Cd/tmp

[Root @ www tmp] # mkdir test <= create a new directory named test

[Root @ www tmp] # mkdir test1/test2/test3/test4

Mkdir: cannot create directory 'test1/test2/test3/test4': No such file or directory <= cannot directly create this directory!

[Root @ www tmp] # mkdir-p test1/test2/test3/test4 # added this-p option to help you create multi-layer directories on your own!

Example: create a directory with the permission of rwx -- x

[Root @ www tmp] # mkdir-m 711 test2

[Root @ www tmp] # ls-l drwxr-xr-x 3 root 4096 Jul 18 test drwxr-xr-x 3 root 4096 Jul 18 test1 drwx -- x -- x 2 root 4096 Jul 18 :54 test2

# Take a closer look at the permission section above. If-m is not added to force attribute configuration, the system will use the default attribute. # What are your default attributes? This can be understood through the umask introduced below! Pai_^

Rmdir (delete an empty directory)

   

[Root @ www ~] # Rmdir [-p] Directory Name

Option and parameter:-p: deleted together with the "empty" directory at the upper level

Example: Delete the directory created in the mkdir example (under/tmp!

[Root @ www tmp] # ls-l <= How many directories exist?

Drwxr-xr-x 3 root 4096 Jul 18 test drwxr-xr-x 3 root 4096 Jul 18 test1 drwx -- x 2 root 4096 Jul 18 test2

[Root @ www tmp] # rmdir test <= can be deleted directly. No problem

[Root @ www tmp] # rmdir test1 <= because there is still content, it cannot be deleted!

Rmdir: 'test1': Directory not empty

[Root @ www tmp] # rmdir-p test1/test2/test3/test4

[Root @ www tmp] # ls-l <= You can see that test and test1 are missing in the output below!

Drwx -- x 2 root 4096 Jul 18 :54 test2

# Look! With the-p option, you can immediately delete test1/test2/test3/test4 ~

# Note that this rmdir can only "delete empty directories!

5. View processes and services

   

List all services:

Chkconfig -- list [name]

View the status of a specific service

Service servicename status

View Processes

Ps a shows all programs on the current terminal

For example, the most commonly used is ps aux. Then, use the grep command in the pipeline to filter out specific processes, and then perform operations on specific processes.

Ps aux | grep program_filter_word, ps-ef | grep tomcat

Ps-ef | grep java | grep-v grep shows all java processes, removing the current grep process.

Rpm-qa | grep tomcat check whether tomcat is installed

6. nastat is used to view and display various network-related information, such as network connection, route table, and interface status.

For example

View All tcp ports with nastat-

View all ports in nastat-

View All udp ports in nastat-au

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.