1. Basic common commands
1. See what files are in the directory> ls//list to see what files are in the "current" directory> ls Directory//view file information in the specified directory2. Directory switch >CD directory name>CD.//Parent Directory Switch>CD ~//back to the user's home directory3. Get the directory location for the current operation>pwd4. User switch su user name> Su-//switch to root user> Su-root//Ibid .Su Root//root user switch, in some Linux system effect is: The user is root, permissions are normal> Su Ordinary users//There's no "horizontal line."> Exit//back to previous user //Su and exit are paired, and if more than one SU is used, it will cause the user to overlayJinnan-->root-->jinnan-->root-->Jinnan5. View current manipulator Information> WhoAmI//Who am I ?6. Desktop mode and command mode switching (root user action)># Init 3 ># init 5 7. Viewing the contents of a file> Cat filename//output file contents to Terminal view8. View the size of the file occupying disk space> du-h File
2. Directory Operations
1) Create directory make directory>mkdir dirname> mkdir dir/newdir//Create a newdir under Dir to create a multilevel directory, if the number of "new directories" is greater than 1, set "-P"Parameters> Mkdir-p Newdir/newdir/newdir//Create a multilevel recursive directory> Mkdir-p Dir/newdir/newdir//Create a multilevel recursive directory> Mkdir-p dir/newdir/newdir/newdir 2) (File/directory) move-change name operation move > MV Dir1 dir2//Dir1 move to the DIR2 directory and change the name to "formerly known"> MV Dir1 dir2/newdir//dir1 move to the DIR2 directory and change the name to "Newdir" > MV dir1 newdir//Dir1 move to the current directory and change the name to "Newdir"> MV Dir1/dir2 DIR3/DIR4//Dir2 move to the DIR4 directory and change the name to "formerly known"> MV Dir1/dir2 dir3/dir4/newdir//dir2 move to DIR4 directory and change to name "Newdir" 3) (File/directory) copy-change name operation copyfile Copy> CP file1 DIR1//File1 was copied to Dir1 and changed to name "formerly known"> CP file1 dir1/newfile//file1 is copied to Dir1 and renamed "NewFile" > CP dir1/file1 DIR2/DIR3//File1 was copied to DIR3 and changed to name "formerly known"> CP dir1/file1 dir2/dir3/newfile//file1 is copied to Dir3 and renamed "NewFile"directory replication, unified settings-r parameter recursive recursively (ignores directory hierarchy)> Cp-r dir1 dir2//Dir1 was copied to Dir2 and changed to name "formerly known"> Cp-r dir1 dir2/newdir//dir1 was copied to Dir2 and renamed "Newdir" > Cp-r dir1/dir2 DIR3/DIR4//Dir2 was copied to DIR4 and changed to name "formerly known"> Cp-r dir1/dir2 dir3/dir4/newdir//dir2 was copied to DIR4 and renamed "Newdir" > Cp-r dir1/dir2 newdir//dir2 was copied to the Previous directory, and renamed "Newdir" 4) Delete (file/directory) > RM file//Deleting Files> Rm-r dir//Delete directory> RM-RF filename//recursive force recursive, forcibly deleting files //-F force avoids "go to directory, delete hidden files" prompt> RM-RF///Kill Your self
3. File operation
1) View Files> cp/etc/passwd.///Copy the passwd file to the current directory> Cat filename//output file contents to Terminal> More filename//tap Enter to view the contents of the file line by row //not supported to look back //Q Key, exit view> Less filename//View the contents of a document by using the "up and down" key //support back to see, Q Key Exit View> head-n filename//View the top n rows of a document> tail-n filename//View the end of the document n lines of content> WC filename//calculate the number of file lines2) to create a file> Touch filename//Create a file3) Append content to file echo content>/>> files > Echo dog > Animal.txt//Append the dog content to the Animal.txt file in "Overwrite write" mode //If the Animal.txt file does not exist, it will "automatically create"> Echo HTC >> order.txt//set HTC content to the Order.txt file in "Append only" mode //The Order.txt file does not exist and is automatically created
4. User action (Root)
Users: User add: Add Modify: MoD (ify) Delete: del (ete) config file:/etc/passwd1) Increased user Useradd> Useradd Xiaogang//Adding a Xiaogang user creates a group with the same name //groups with the same name are created without setting the user's group> useradd-g Group number Liming//Create liming users and set their groups (avoid creating groups with the same name)> Useradd-u User number-G group number-d Home Directory user name2) Modify User Usermod> Usermod-u User number-G group number-D home Directory-l new name User name//If you modify your home directory, you need to create it manually (different from adding users)3) Delete User Userdel> Userdel User Name///etc/passwd Configuration user information will be deleted (keep home directory, can be deleted manually)> Userdel-r User Name//user information and their home directories are deleted
5. Group operations (Root)
Group: Group profile:/etc/1) add group Groupadd // Create a music group 2) Change Group Groupmod > Groupmod-g Group number-n new name Group name 3) remove group Groupdel > Groupdel Group name //< user information is available under the/c13> group, no deletion
6. Vim Use
Vim filename // Open or new file I // in the current Word match either insert text a // Add text after the current character o // insert a blank line after the current line ESC // Switch to command mode : Wq or: x // Save and exit : Q // exit, for modified file : q! // do not save file, exit directly
Common Linux Commands