Accumulate commands common to Linux

Source: Internet
Author: User
Tags readable rsync shebang

Accumulate commands common to Linux

Major records of problems encountered in daily life, to record:

    • there are ^m in files in Linux
      The shell command TR can be used to achieve the removal, the specific command is as follows:
  -v|-d"^M"> targetfile
  • Select a word in vim
    After ESC, use W or WI or Vwi to select a word

  • move the cursor quickly in the console
    1. Delete
    1.1 Ctrl + D deletes the character at the cursor location equivalent to VIM x or DL
    1.2 Ctrl + H deletes the character in front of the cursor, which corresponds to the HX or DH in vim.
    1.3 Ctrl + K removes all characters after the cursor equivalent to VIM in d,shift+$
    1.4 Ctrl + U removes all characters in front of the cursor equivalent to VIM d,shift+^
    1.5 Ctrl + W DELETE cursor before a word equals vim in db
    1.6 Ctrl + Y restores Ctrl+u characters that were deleted when they were last executed
    1.7 Ctrl +? Undo previous input
    1.8 ALT + R undo Previous action
    1.9 Alt + D Delete the post word at the cursor location
    2. Mobile
    2.1 Ctrl + A moves the cursor to the beginning of the command line equivalent to Vim shift+^
    2.2 Ctrl + E moves the cursor to the end of the command line at the equivalent of vim shift+$
    2.3 Ctrl + F cursor moves backwards one character equivalent to Vim in L
    2.4 Ctrl + B cursor moves forward one character equivalent to Vim in H
    2.5 Ctrl + ARROW key left cursor moves to the beginning of the previous word
    2.6 Ctrl + ARROW key right cursor moves to the end of the next word
    2.7 Ctrl + X jumps between the last character of the cursor and the character where the current cursor is located
    2.8 in Vim in the command input mode, enter GG, you can quickly jump to the beginning of the file
    2.9 in vim in the command input mode, enter GG, you can quickly jump to the end of the file
    3. Statistics
    3.1 For example, in Vim to count the number of a string, you can use the command

    :%s/Name//gn
  • prevent a file from being deleted
    1. Use a shell command to prevent files under 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(){    "[email protected]" trash/}oralias rm=‘cp [email protected] ~/backup; rm [email protected]‘
    • Data Synchronization Command
#!/bin/shDate- D ' Now '>/mnt/hd/data/log/rsync.log index=1 while: DoRSYNC-AZVH--compress-level=0--progress [email protected]:/mnt/hd/data/priceadj_data//mnt/hd/data/priceadj_data/>>/mnt/hd/data/log/ Rsync.logif[ $?-ne 0]; ThenSleep5MElse         Break    fi     Let "index++"    if[$index -eq 5]; ThenCurl- D "Operator=alert&phone=number&msg=rsync-dell-data-failed" "Http://ip:port/sendmessage"        Echo "rsync data Failed!">>/mnt/hd/data/log/rsync.logExit 1    fi DoneDate- 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
    • Removing duplicate rows from a file in Linux
| uniq > save_path
    • Update Linux system time
sudo ntpdate cn.pool.ntp.org

NTP servers in the Asian region
1. bangladesh-bd.pool.ntp.org
2. china-cn.pool.ntp.org
3. Hong kong-hk.pool.ntp.org
4. india-in.pool.ntp.org
5. indonesia-id.pool.ntp.org
6. iran-ir.pool.ntp.org
7. israel-il.pool.ntp.org
8. japan-jp.pool.ntp.org
9. korea-kr.pool.ntp.org
Ten. malaysia-my.pool.ntp.org
Philippines-ph.pool.ntp.org.
Singapore-sg.pool.ntp.org.
Taiwan-tw.pool.ntp.org.
Thailand-th.pool.ntp.org.
Turkey-tr.pool.ntp.org.
Arab emirates-ae.pool.ntp.org

    • Complete word matching in vim
使用命令行输入模式/\<这里输入你要匹配的单词\>如果在单文件中使用进行查找和匹配直接使用在命令输入模式下 对某个单词使用 *
    • Intranet data transfer and backup using SCP and rsync
RSYNC-AZVH--delete--compress-level=0--progress [email protected] (IP): file_path save_path >> log_path parameter explanation:-V:--verbose Increase verbosity--info=FLAGS fine-grained informational verbosity--debug=FLAGS fine-grained debug verbosity--msgs2stderr Special output handling  for debugging-A:--archive archive mode; Equals-rlptgod (no-H,-A,-X)--no-option turn off an implied option (e.g.--no-D)-Z:--compress compress file data during the transfer--compress-level=NUM explicitly set compression level--skip-compress=LIST skip compressing files with suffix  in LIST -h:--human-readable Output numbers  in a human-readable format--progress Show progress during transfer--delete Delete extraneous files from dest dirs
scp mode remote_username@remote_hostname(or ip):remote_file_path dest_file_path >> run_log_pathexample:name@host:/mnt/hd/data/code/shell$ scp sql_rsync.sh name@host:/tmp/name@host‘s password:sql_rsync.sh                                                                                                                                                100%  149     0.2KB/s   00:00[email protected]:/mnt/hd/data/code/shell$

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Accumulate commands common to Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.