Accumulate common linux commands and 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
2.8 In the command input mode of vim, enter gg to quickly jump to the beginning of the file.
2.9 In the command input mode in vim, enter GG to quickly jump to the end of the file
3. Statistics
3.1 for example, to count the number of strings in vim, you can use the command
:%s/Name//gn
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 $@'
- Data Synchronization command
#!/bin/sh date -d 'now' > /mnt/hd/data/log/rsync.log index=1while :do rsync -azvh --compress-level=0 --progress gpx@ip:/mnt/hd/data/PriceAdj_data/ /mnt/hd/data/PriceAdj_data/ >> /mnt/hd/data/log/rsync.log if [ $? -ne 0 ];then sleep 5m else break fi let "index++" if [ $index -eq 5 ];then curl -d "operator=alert&phone=number&msg=rsync-dell-data-Failed" "http://ip:port/sendmessage" echo "rsync data Failed !" >> /mnt/hd/data/log/rsync.log exit 1 fidonedate -d 'now' > /mnt/hd/data/log/log_save_dateData.log nohup python /mnt/hd/data/code/load_Today_Data.py >> /mnt/hd/data/log/log_save_dateData.log
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.