[Fine] Common Commands of Linux System

It's worth accumulating bit by bit


Files and Directories  
cd /home into the '/home' directory'  

cd .. go back to the previous directory  

cd ../.. go back two levels up  

cd into the personal home directory  
cd ~user1 into the personal home directory  

cd - return to the last directory  

pwd show working path  

ls to view files in a directory

mkdir dir1 creates a directory called 'dir1''  

mkdir dir1 dir2 creates two directories at the same time  

mkdir -p /tmp/dir1/dir2 creates a directory tree  

rm -f file1 delete a file called 'file1''  

rmdir dir1 removes a directory called 'dir1' '  
rm -rf dir1 removes a directory called 'dir1' and also removes its contents  

rm -rf dir1 dir2 deletes both directories and their contents at the same time  

mv dir1 new_dir rename/move a directory  
cp file1 file2 copy a file  
cp dir/* . Copy all files in a directory to the current working directory  

cp -a /tmp/dir1 . Copy a directory to the current working directory  

cp -a dir1 dir2 copy a directory (-a is a copy of the original log including attributes)

cp -r dir1 dir2 Copy a directory (-r attributes such as modification time may change after copying)

file search  
find / -name file1 start from '/' into the root file system to search for files and directories  

find / -user user1 Search for files and directories belonging to user 'user1'  
find /home/user1 -name \*.bin Search for files ending with '.bin' in directory '/home/user1'

File operation vi/vim

file mode:

general mode

Switch to edit mode: enter i

edit mode

Switch to normal mode: type esc

Switch to command mode: enter -shift+:

command mode

Switch to normal mode: type esc

[/word] Search for the character string with the content of word in the file (search down)
[?word] Search for the character string with the content of word in the file (search up)
[[n]] Indicates the repeated search action, that is, the search for the next A
[[N]] Reverse search for the next

【dd】 Delete the entire line where the cursor is located
【ndd】 Delete the downward n lines where the cursor is located

[yy] Copy the line where the cursor is located
[nyy] Copy the line down n where the cursor is located


[p,P] p means to paste the copied data on the next line of the cursor; P means to paste the copied data on the previous line of the cursor

【u】 Undo the previous operation

【:w】Save the file
【:w!】If the file is read-only, force the file to be saved
【:q】Exit vi
【:q!】Forcibly leave vi without saving
【:wq】Save and leave
【:wq!】Forcibly save After leaving
[:! command] Leave vi temporarily and go to the command line to display the result after executing a command
[:set nu] Display the line number
[:set nonu] Cancel the display of the line number

【v,V】 v:将光标经过的地方反白选择;V:将光标经过的行反白选择
【[Ctrl] + v】 块选择,可用长方形的方式选择文本
【y】 将反白的地方复制到剪贴板
【d】 将反白的内容删除

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325811542&siteId=291194637