Linux instruction learning notes (1): linux instruction learning notes
1. view the files/directories in the directory
> Ls // list directory file information
> Ls-l or ll // list-list view the directory file with "details"
> Ls-a // list-all: view the "all" Directory (including hidden files) File
> Ls-al // list-all list to view the "all" (including hidden files) file in the directory, which is displayed as "details"
> Ls directory // view the files in the specified directory
> Ls-I // view the file index number
2. Switch Directories
> Cd dirname // switch the Directory
> Cd .. // switch to the parent directory
> Cd ~ Or cd // directly switch to the Home Directory of the current user
3. view the complete operation location
> Pwd
4. User Switching
> Su-or su-root // switch to the root user
> Exit // return to the original user
> Su user name // Common User Switch
Multiple su commands may overlay the user ":
(It is best to match su and exit)
Jinnan ---> root ---> jinnan
5. Check who the current user is.
> Whoami
6. Gui and command interface Switch
Root users can switch
> # Init 3
> # Init 5
7. view the execution program file corresponding to a command
> Which command
8. Directory-related operations
1) create directory make directory
> Mkdir directory name
> Mkdir-p newdir/newdir // recursively create multiple continuous Directories
// Use the-p parameter if the number of new multi-level directories is greater than or equal to 2.
Mkdir dir/newdir // do not use the-p Parameter
Mkdir-p dir/newdir // use the-p Parameter
Mkdir-p newdir/newdir // use the-p Parameter
2) move directories (Files And Directories) move
> Mv dir1 dir2 // move dir1 to the dir2 directory
> Mv dir1/dir2 dir3 // move dir2 to the dir3 directory
> Mv dir1/dir2 dir3/dir4 // move dir2 to the dir4 directory
> Mv dir1/dir2. // move dir2 to the current directory
3) Change the name (file and directory)
> Mv dir1 newdir // modify dir1's name to newdir
Mv is a command that combines "move" and "RENAME ".
> Mv dir1./newdir // dir1 move to the current directory and change the name to newdir.
> Mv dir1/dir2 dir3 // dir2 is moved to the dir3 directory and renamed as "Original Name"
> Mv dir1/dir2 dir3/newdir // dir2 move to the dir3 directory and change its name to "newdir"
> Mv dir1/dir2 dir3/dir4 // dir2 is moved to the dir4 directory and renamed as "Original Name"
> Mv dir1/dir2 dir3/dir4/newdir // dir2 move to the dir4 directory and change its name to "newdir"
4) copy (rename) (file and directory) copy
① File Replication
> Cp file1 dir/newfile2 // file1 is copied to the dir directory and renamed "newfile2"
> Cp file1 dir // file1 is copied to the dir directory and renamed as "Original Name"
> Cp dir1/filea dir2/newfile // filea is copied to the dir2 directory and renamed "newfile"
② Directory replication (you need to set the-r [recursive recursion] parameter to ignore the directory hierarchy)
> Cp-r dir1 dir2 // dir1 is copied to the dir2 directory and renamed as "Original Name"
> Cp-r dir1/dir2 dir3/newdir // dir2 is copied to the dir3 directory and renamed "newdir"
> Cp-r dir1/dir2 dir3/dir4 // dir2 is copied to the dir4 directory and renamed as "Original Name"
> Cp-r dir1/dir2 dir3/dir4/newdir // dir2 is copied to the dir4 directory and renamed "newdir"
> Cp-r dir1.../newdir // dir1 is copied to the two directories and renamed "newdir"
⑤ Delete (Files And Directories) remove
> Rm file
> Rm-r directory //-r [recursive recursion] recursively deletes a directory
> Rm-rf file/directory //-r force recursively enforces File Deletion
Force, no additional prompts
Rm-rf/
9. File Operations
1) view the File Content
Cat filename // print the file content to the Output Terminal
More filename // press enter to view the content of each row of the file.
// Check from the first line by default
// Playback is not supported
// Exit q.
Less // use the "up/down" key to view the content of each part of the file
// Supports playback.
// Exit q.
Head-n filename // view the first n rows of the file
Tail-n filename // view the end n lines of the file
Wc filename // view the number of objects
2) create a file
> Touch dir1/filename
> Touch filename
3) Append content to the file
> Echo content> file name // APPEND "content" to "file" in [overwrite] Mode"
> Echo content> file name // write "content" in the form of [append] To "file"
(A file will be created if the file does not exist)
10. user operations
Configuration File:/etc/passwd
1) create user add
> # Useradd
> # Useradd liming // create a liming user and create a group with the same name.
> # Useradd-g group number username // set the user group to avoid creating a group with the same name.
> # Useradd-g group no.-u user No.-d home directory username
2) modify user modify
> # Usermod-g group no.-u user No.-d home directory-l new name username
(You must manually create the directory when modifying the home directory)
3) delete user delete
> # Userdel username
> # Userdel-r username // Delete the user's home directory while deleting the user
4) set a password for the user to log on to the system.
> Passwd User Name
11. Group operations
Configuration File:/etc/group
1) Create group add
> # Groupadd music
> # Groupadd movie
> # Groupadd php
2) modify group modify
> # Groupmod-g gid-n new name groupname
3) delete group delete
> # Groupdel groupname // if a user exists under the group, the group cannot be deleted.
12. view the configurable parameters of the command.
> Man command
13. Set permissions for files
1) grant permissions in relative letter Mode
// Set permissions for one group. permissions for other groups are not changed.
Chmod command
Chmod u + rwx filename // Add the "read, write, and execute" permission to the filename file owner
Chmod g-rx filename // Delete the "read and execute" permission for the same group of users in the filename File
Chmod u +/-rwx, g +/-rwx, o +/-rwx filename
Note:
① Each unit "+"-"can only use one
② You can set permissions for one or more groups at the same time, and use "," to separate groups.
③ Each unit can have one or more permissions in rwx.
> Chmod u + w, g-rx, o + rw filename // Add write permissions to the filename file owner, delete read and execute permissions in the same group, and add read and write permissions to other groups.
> Chmod u + w, u-x filename // "add write permission" to the filename file owner and "delete execution permission"
Chmod +/-rwx filename // ignore a specific group and Set permissions for all groups.
> Chmod + rw filename // Add the "read and write" permission to all filename users
2) Set permissions in absolute numeric Mode
R read: 4 w write: 2 x execution: 1
0: no permission
1: Run
2: Write
3: Write and execute
4: Read
5. read and execute
6. Read and Write
7: read, write, and execute
Chmod ABC filename // ABC indicates the numerical permissions of the master, the same group, and other users.
> Chmod 753 filename // read, write, and execute by the master; read and execute in the same group; write and execute in other groups
Note: When the permission to be modified is relatively "relatively small", the "letter" method is used.
On the contrary, when the permission changes "a lot", the "Number" method is used.
14. Search for content in the file
Grep Content File searched
> Grep hello passwd // search for hello content in the passwd file
// Prints the content of the row where hello is located to the terminal for display.
15. disk space occupied by computing files
> Du-h file (directory)
16. File Search
Find directory option value...
1)-the name option is searched by name
> Find/-name passwd [full name] // "recursively traverse" all directories of the system and search for files with names equal to "passwd"
> Find/-name "pas *" [fuzzy search] // In all directories of the system, fuzzy search for a file whose name is "pas"
> Find/-name "* er *" // the file name must contain the word "er ".
2) restrict the directory levels to be searched-maxdepth-mindepth
-Maxdepth: restrict the deepest directories to be searched.
-Mindepth: restrict the shortest directories to be searched.
> Find/-maxdepth 4-name passwd
> Find/-maxdepth 4-mindepth 3-name passwd
3) Search for files based on the size
-Size +/-Number
+ Indicates that the size is greater than a certain range.
-Indicates that the size is smaller than a certain range.
Size unit:
-Size 5 // The unit is "512 bytes" 5*512 bytes
-Size 10c // The unit is 10 bytes.
-Size 3 k // unit: "kilobytes" 3*1024 bytes
-Size 6 M // The unit is "1024 * kilobytes" 6 M MB
> Find./-size 14c // search for files of 14 bytes in the current directory
> Find/-size + 50 M // search for files larger than 50 M in all directories of the system
17. Program port problems
Netstat-apn view all ports and usage
Netstat-apn | grep svn search in all
18. Check whether software is installed in the system.
View the software installed by rpm
Rpm-qa | grep tomcat
How to view software installed by make & make install
Find-name tomcat
Reference: http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/12/2208205.html
19. view the current process information
Ps command
-A: displays all processes.
-U root specifies all processes of the User root
-Au displays more detailed information
-Aux: Show All itineraries containing other users
Reference: http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html