Accumulate common linux commands
Accumulate common linux commands
Record problems encountered in daily life:
Linux files contain ^ M
The shell command tr can be used for removal. The specific command is as follows:
cat -v yourfile | tr -d "^M" > targetfile
Select a word in VIM
After ESC, you can select a word using w, wi, or vwi.
Quickly move the cursor in the console
1. Delete
1.1 ctrl + d Delete the character at the cursor position, which is equivalent to x or dl in VIM
1.2 ctrl + h Delete the character before the cursor position, which is equivalent to hx or dh in VIM
1.3 ctrl + k Delete All characters behind the cursor, which is equivalent to d, shift + $
1.4 ctrl + u Delete All characters before the cursor, which is equivalent to d, shift + ^ in VIM
1.5 ctrl + w Delete the word before the cursor is equivalent to db in VIM
1.6 ctrl + y resume ctrl + u characters deleted during last execution
1.7 ctrl +? Undo previous input
1.8 alt + r undo the previous action
1.9 alt + d Delete the word behind the cursor position
2. Move
2.1 ctrl + a move the cursor to the beginning of the command line, which is equivalent to shift + ^ in VIM
2.2 ctrl + e moving the cursor to the end of the command line is equivalent to shifting in VIM + $
2.3 ctrl + f move the cursor one character backward, equivalent to l in VIM
2.4 ctrl + B move the cursor forward a character equivalent to h in VIM
2.5 ctrl + left arrow keys move cursor to the beginning of the previous word
2.6 ctrl + Right-click the arrow key and move the cursor to the end of the last word
2.7 ctrl + x jump between the character of the last cursor and the character of the current cursor
Prevent a file from being deleted
1. Use a shell command to prevent files from being deleted.
sudo chattr +a Downloadscd Downloadsrm Ngix.pdfmv: cannot move ‘Ngix.pdf’ to ‘/home/gpx/.trash/Ngix.pdf’: Operation not permittedsudo rm Ngix.pdfrm: cannot remove ‘Ngix.pdf’: Operation not permitted
2. Use the alias command to remove rm
alias rm='rm -i'oralias rm=trashtrash(){ mv $@ trash/}oralias rm='cp $@ ~/backup; rm $@'