積累linux常用命令大全
本人記憶力有限,就把平時在項目中遇到的linux常用命令分享給大家。
Linux常用命令全集 http://www.dbjr.com.cn/linux/
linux文件中存在^M
使用shell命令tr可以實現(xiàn)去除,具體命令如下:
cat -v yourfile | tr -d "^M" > targetfile
VIM中選定某個單詞
在ESC之后,使用w或者wi或者vwi可以選擇某個單詞
在控制臺中快速移動光標(biāo)
1.刪除
1.1 ctrl + d 刪除光標(biāo)所在位置上的字符相當(dāng)于VIM里x或者dl
1.2 ctrl + h 刪除光標(biāo)所在位置前的字符相當(dāng)于VIM里hx或者dh
1.3 ctrl + k 刪除光標(biāo)后面所有字符相當(dāng)于VIM里d,shift+$
1.4 ctrl + u 刪除光標(biāo)前面所有字符相當(dāng)于VIM里d,shift+^
1.5 ctrl + w 刪除光標(biāo)前一個單詞相當(dāng)于VIM里db
1.6 ctrl + y 恢復(fù)ctrl+u上次執(zhí)行時刪除的字符
1.7 ctrl + ? 撤消前一次輸入
1.8 alt + r 撤消前一次動作
1.9 alt + d 刪除光標(biāo)所在位置的后單詞
2.移動
2.1 ctrl + a 將光標(biāo)移動到命令行開頭相當(dāng)于VIM里shift+^
2.2 ctrl + e 將光標(biāo)移動到命令行結(jié)尾處相當(dāng)于VIM里shift+$
2.3 ctrl + f 光標(biāo)向后移動一個字符相當(dāng)于VIM里l
2.4 ctrl + b 光標(biāo)向前移動一個字符相當(dāng)于VIM里h
2.5 ctrl + 方向鍵左鍵 光標(biāo)移動到前一個單詞開頭
2.6 ctrl + 方向鍵右鍵 光標(biāo)移動到后一個單詞結(jié)尾
2.7 ctrl + x 在上次光標(biāo)所在字符和當(dāng)前光標(biāo)所在字符之間跳轉(zhuǎn)
2.8 在vim中的命令輸入模式中,輸入gg,可以快速跳轉(zhuǎn)到文件開頭
2.9 在vim中的命令輸入模式中,輸入GG,可以快速跳轉(zhuǎn)到文件結(jié)尾
3.0 在vim中返回上一個的編輯的位置,在輸入命令模式使用 ctrl+o
3.1 在vim中返回下一個的編輯的位置,在輸入命令模式使用 ctrl+i
3.統(tǒng)計
3.1 例如在vim中統(tǒng)計某個字符串的數(shù)量,可以使用命令
:%s/Name//gn
防止被某個文件被刪除
1.使用一個shell命令來防止文件下的文件不能被刪除
sudo chattr +a Downloads cd Downloads rm Ngix.pdf mv: cannot move ‘Ngix.pdf' to ‘/home/gpx/.trash/Ngix.pdf': Operation not permitted sudo rm Ngix.pdf rm: cannot remove ‘Ngix.pdf': Operation not permitted
2.使用alias命令來去除rm
alias rm='rm -i' or alias rm=trash trash() { mv "$@" trash/ } or alias rm='cp $@ ~/backup; rm $@'
數(shù)據(jù)同步命令
#!/bin/sh date -d 'now' > /mnt/hd/data/log/rsync.log index=1 while : 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 fi done date -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中去除文件中的重復(fù)行
sort -n Yourfile | uniq > save_path
更新Linux系統(tǒng)時間
sudo ntpdate cn.pool.ntp.org
亞洲地區(qū)的ntp服務(wù)器
. Bangladesh — bd.pool.ntp.org . China — cn.pool.ntp.org . Hong Kong — hk.pool.ntp.org . India — in.pool.ntp.org . Indonesia — id.pool.ntp.org . Iran — ir.pool.ntp.org . Israel — il.pool.ntp.org . Japan — jp.pool.ntp.org . Korea — kr.pool.ntp.org . 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 . United Arab Emirates — ae.pool.ntp.org
在vim中進行完整單詞的匹配
使用命令行輸入模式
/\<這里輸入你要匹配的單詞\>
如果在單文件中使用進行查找和匹配
直接使用在命令輸入模式下 對某個單詞使用 *
使用scp和rsync進行數(shù)據(jù)的內(nèi)網(wǎng)數(shù)據(jù)傳輸和備份
rsync -azvh --delete --compress-level=0 --progress username@hostname(ip):file_path save_path >> log_path
參數(shù)解釋:
-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_path example: 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 name@host:/mnt/hd/data/code/shell$ 接下來給大家總結(jié)了10條linux常用命令
1.》將原文件清空,并且內(nèi)容寫入到文件中,》》將內(nèi)容放到文件的尾部
echo “aa” 》 test.txt 和 echo “bb” 》》 test.txt
2 給組用戶和其他用戶添加寫的權(quán)限
chmod go+w -R /home/zhangy
3. 列出歸檔內(nèi)容
tar -tzvf test.tar.gz
4.查看文件列表大小
du -ah
5. 查看所有文件的大小總和
du -sh
6.數(shù)學(xué)運算
echo ‘1+2'|bc -l
7. //查看linux內(nèi)核等的一些信息
uname -a
8.壞道掃描時顯示進度
badblocks -s /dev/sda
9.查看命令的運行時間
time command
10.按時間的倒序排序
ls -lrt
以上就是linux常用的命令,希望大家喜歡。
- Linux 入門常用命令 password — 修改密碼,改變用戶
- Linux 中 CURL常用命令詳解
- linux系統(tǒng)安裝git及git常用命令
- 很實用的Linux 系統(tǒng)運維常用命令及常識(超實用)
- Linux常用命令全集(超全面)
- linux下防火墻開啟某個端口號及防火墻常用命令使用(詳解)
- Linux操作系統(tǒng)操作MySQL常用命令小結(jié)
- Linux 常用命令大全(經(jīng)典)
- Linux下find和grep常用命令及區(qū)別介紹
- LINUX入門級常用命令20條整理
- 日常整理linux常用命令大全(收藏)
- Linux常用命令last的使用方法詳解
- 詳解Linux防火墻iptables禁IP與解封IP常用命令
- linux 入侵常用命令匯編
- 基于Linux調(diào)試工具strace與gdb的常用命令總結(jié)
- Linux系統(tǒng)信息查看常用命令
- 新手入門級linux系統(tǒng)常用命令大全
- 最新Linux下安裝tomcat8圖解過程
相關(guān)文章
Linux?shell字符串截取、替換、刪除以及trim代碼示例
在Shell編程中,截取、替換、刪除字符串是非常常見的操作,這篇文章主要給大家介紹了關(guān)于Linux?shell字符串截取、替換、刪除以及trim的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03Shell腳本導(dǎo)入導(dǎo)出數(shù)據(jù)的項目示例
在工作中,很多場景都會涉及到數(shù)據(jù)的導(dǎo)入導(dǎo)出,本文就介紹一下使用Shell腳本導(dǎo)入導(dǎo)出數(shù)據(jù)的項目示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04