本人記憶力有限,就把平時在項目中遇到的linux常用命令分享給大家。
Linux常用命令全集 http://www.companysz.com/linux/
linux文件中存在^M
使用shell命令tr可以實現去除,具體命令如下:
VIM中選定某個單詞
在ESC之后,使用w或者wi或者vwi可以選擇某個單詞
在控制臺中快速移動光標
1.刪除
1.1 ctrl + d 刪除光標所在位置上的字符相當于VIM里x或者dl
1.2 ctrl + h 刪除光標所在位置前的字符相當于VIM里hx或者dh
1.3 ctrl + k 刪除光標后面所有字符相當于VIM里d,shift+$
1.4 ctrl + u 刪除光標前面所有字符相當于VIM里d,shift+^
1.5 ctrl + w 刪除光標前一個單詞相當于VIM里db
1.6 ctrl + y 恢復ctrl+u上次執行時刪除的字符
1.7 ctrl + ? 撤消前一次輸入
1.8 alt + r 撤消前一次動作
1.9 alt + d 刪除光標所在位置的后單詞
2.移動
2.1 ctrl + a 將光標移動到命令行開頭相當于VIM里shift+^
2.2 ctrl + e 將光標移動到命令行結尾處相當于VIM里shift+$
2.3 ctrl + f 光標向后移動一個字符相當于VIM里l
2.4 ctrl + b 光標向前移動一個字符相當于VIM里h
2.5 ctrl + 方向鍵左鍵 光標移動到前一個單詞開頭
2.6 ctrl + 方向鍵右鍵 光標移動到后一個單詞結尾
2.7 ctrl + x 在上次光標所在字符和當前光標所在字符之間跳轉
2.8 在vim中的命令輸入模式中,輸入gg,可以快速跳轉到文件開頭
2.9 在vim中的命令輸入模式中,輸入GG,可以快速跳轉到文件結尾
3.0 在vim中返回上一個的編輯的位置,在輸入命令模式使用 ctrl+o
3.1 在vim中返回下一個的編輯的位置,在輸入命令模式使用 ctrl+i
3.統計
3.1 例如在vim中統計某個字符串的數量,可以使用命令
防止被某個文件被刪除
1.使用一個shell命令來防止文件下的文件不能被刪除
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.使用alias命令來去除rm
alias rm='rm -i'oralias rm=trashtrash(){ mv "$@" trash/}oralias rm='cp $@ ~/backup; rm $@'
數據同步命令
#!/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
linux中去除文件中的重復行
更新Linux系統時間
亞洲地區的ntp服務器
在vim中進行完整單詞的匹配
使用命令行輸入模式
//<這里輸入你要匹配的單詞/>
如果在單文件中使用進行查找和匹配
直接使用在命令輸入模式下 對某個單詞使用 *
使用scp和rsync進行數據的內網數據傳輸和備份
參數解釋:
-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 dirsscp 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:00name@host:/mnt/hd/data/code/shell$接下來給大家總結了10條linux常用命令
1.》將原文件清空,并且內容寫入到文件中,》》將內容放到文件的尾部
2 給組用戶和其他用戶添加寫的權限
3. 列出歸檔內容
4.查看文件列表大小
5. 查看所有文件的大小總和
6.數學運算
7. //查看linux內核等的一些信息
8.壞道掃描時顯示進度
9.查看命令的運行時間
10.按時間的倒序排序
以上就是linux常用的命令,希望大家喜歡。
新聞熱點
疑難解答