Linux system: summary of common Linux system management commands
Source: GitHub·Click here|| GitEE·Click here
First, directory instructions 1, create a directory make directorymkdir directory name //mkdir spring, create a spring folder mkdir -p file/file/file //recursively create multi-level relational directory mkdir dir/newdir //do not use recursion mkdir -p dir/newdir/newdir //use recursion 2, move directory movemv dir1 dir2 //Move dir1 directory to dir2 directory mv dir1/dir2 dir3 //Move dir2 directory to dir3 directory mv dir1/dir2 dir3/dir4 //Move dir2 directory to dir4 directory mv dir1/dir2 ./ //Move dir2 to the current directory mv dir1/dir2 dir3/dir4 //dir2 moved to dir4 directory and changed the name to "original name"mv dir1/dir2 dir3/dir4/newdir //dir2 Move to dir4 directory and change the name to "newdir"3. Change the file name mv dir1 newdir1 //modify dir1 name to newdir14 copy
copy files
cp file1 dir/file2 //Copy file1 to dir directory and rename file2cp file1 dir //file1 is copied to dir directory and renamed "cp dir1/file1 dir2/newfile //file1 is copied to dir2 directory and renamed"newfile"Copy directory: -r Ignore directory hierarchy cp -r dir1 dir2 //dir1 is copied to dir2 and renamed "cp -r dir1/dir2 dir3/newdir //dir2 is copied to dir3 and renamed"newdir"cp -r dir1/dir2 dir3/dir4 //dir2 is copied to dir4 directory and renamed "original name"cp -r dir1/dir2 dir3/dir4/newdir //dir2 is copied to dir4 directory and renamed "newdir"cp -r dir1../../ newdir //dir1 is copied to the upper two directories, and changed to "newdir"5. Delete the removerm file //delete regular file "" //y: delete,n: cancel operation rm -r hierarchical directory //recursively delete directory rm -rf directory/file //forcibly delete files or directories 2. file commands 1. view file contents cat filename //Print file contents to output terminal more filename //View the file line by line by typing Enter //default to start viewing from the first line //no support for review //Enter q to exit view less filename //View the contents of each part of the file by using the "up, down, left and right" keys //Support Looking Back //Enter q to exit view head -n filename //View the first n lines of a file tail -n filename //View the last n lines of the file wc filename //View the number of lines in a file 2. Create a file touch dir1/filename //Create a file touch filename under the specified path //Create a file in the current directory 3. Add content to the file
If the file doesn't exist, it's created.
echo content > filename //append "content" to "file"echo content>> filename as [overwrite] //Write "content" to "file" in the form of [append] III. User instructions
User action: requires root login of the system
1. Create user add
Configuration file: /etc/passwd
useradduseradd liming //Create liming user and create a group with the same name useradd -g group number username //Set user group to avoid creating a group with the same name useradd -g group number-u user number-d home directory username2. modify user usermodifyusermod -g group number-u user number-d home directory-l new name username3. delete user userdeleteuserdel usernameuserdel -r username //Delete the user and delete his home directory at the same time. 4. Set a password for the user to log in to the system passwd user name. 4. Group operation.
System root login required
1. Create group add
Configuration file: /etc/group
groupadd music2. modify groupmodifygroupmod -g gid -n new name groupname3. delete groupdeletegroupdel groupname //If there is a user under the group, it is forbidden to delete 5. Permission instructions
Linux defines three types of access rights: r, w, and x.
r: indicates that the object is readable, octal representation 4w: indicates that the object is writable, octal representation 2x: indicates that the object is executable, octal representation 1-rwx rwx rwx File Owner Permission User Group Rights Other User Rights
Function: Modify permissions of directories or files
u:user(owner) g:group(belonging group)
o: others a:all
r:read w:write x: execute
chmod 460 test.txt: testFile owner: r, belonging group: rw, other users have no permissions chmod u+w dest_file: Add w permissions to the owner of the target file. chmod u+wx,g+x,o+w dest_file: Add w permissions to the owner of the target file, x permissions to the group to which it belongs, and w permissions to other users of the system. chmod o-w dest_file: removes w permissions for other users of the target file. chmod u=rwx dest_file: Gives the owner the right to rwx. chmod -R 777 /tmp/a , all user rights of all files or directories in directory a including directory are changed to rwx. VI. Notepad instructions
Edit mode is displayed below: - -INSERT- -
Command mode is displayed below: (default nothing is displayed)
The tail mode is displayed below: :wq(exit and save)
1. Edit mode operation a: Move the cursor backward one position i: The cursor and the character do not change o: Give a new line s: Delete the character where the cursor is located 2. Tail line mode operation :q //exit exit editor :w //write Save the modified content :wq //write quit Save changes and exit editor :q! //(do not save) force exit editor :w! //forced preservation :wq! //Force save and exit editing :set number or nu //Set line number :set nonumber or nonu //Set line number :/Content/or/Content //Find specified content Lowercase n (next) Next capital N (next) previous : Numbers //Jump to the line where the number is String substitution cont1 is replaced by cont2 :s/cont1/cont2/ //Replace the first cont1 in the row where the cursor is located :s/cont1/cont2/g //replace all cont1 in the row where the cursor is located :%s/cont1/cont2/g //replace the entire document cont13, command mode operation u cursor movement character-level Up (k) Down (j) Left (h) Right (l) Key Word-level w: word moves to the first letter of the next word e: end Move to the last letter of the next word b: before moves to the first letter of the previous word row-level $: End of line 0: Line Head Paragraph level (flip screen) {: Head of last (current) paragraph }: End of next paragraph Screen level (no flip screen) H: Screen header L: End of screen document-level G: End of document 1G: Document Line 1 nG: Document line n u content deleted dd: Delete Cursor Current Line 2dd: Delete 2 lines backward including the current line ndd: include that current line, delete the next n lines x: Delete cursor character c+w: Delete from the cursor position to the end of the word and enter edit mode u content copy yy: Copy Cursor Current Line 2yy: Copy 2 lines backward including the current line nyy: Copy the next n lines, including the current line p: Paste (delete) copied content u Related shortcut operations u: undo revocation J: Merge upper and lower rows r: Single character substitution . Point: Repeat the last most recent command. 7. Decompress and uncompress command gzip a.txt: gzip compress gzip -d a.txt.gz or gunzip a.txt.gz: decompress bzip2 a: bzip2 compress bunzip2 a.bz2 or bzip2 -d a.bz2: decompress tar -cvf bak.tar.: Package the files in the current directory tar -rvf bak. tar/etc/password: append/etc/password to bak.tar (r)tar -xvf bak.tar: extract tar -zcvf a.tar.gz: pack and compress tar-zxvf a. tar. gz-C/usr: extract tar -ztvf a.tar.gz or zip/unzip: view the contents of the compressed package tar -jcvf a.tar.bz2: pack and compress to bz2tar -jxvf a.tar.bz2: Decompress bz2 VIII. Firewall command 1. Effective after restart: chkconfig iptables on off: chkconfig iptables off 2. Effective immediately, invalid after restart: service iptables start off: service iptables stop IX. System command shell > # grep Keyword Path name Match the information specified in the text shell ># which directive Find the binary file corresponding to the command shell > # ps -A View system active processshell > # du -h target Display the size of disk space occupied by a directory or file in K, M, G (block default =4k) shell > # date -s "2013-09-13 19:42:30" Set the system time shell > # date View system time shell > # df -lh View system partition shell > # kill -9 pid kill the process with the specified process number shortcut key command ctrl + c: stop the process ctrl + l: clear the screen ctrl + r: search history command ctrl + q: exit help "command" or man "command": view internal command help cd ~ or cd: enter the user root directory pwd: view the current directory cd ~cl: enter cl user root directory cd -: return to the original directory cd ~: Go back to the previous directory ls -la: View all files under the root directory of la user XI. Source code address GitHub·Address https://github.com/cicadasmile/linux-system-baseGitEE·Address https://gitee.com/cicadasmile/linux-system-base