溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

總結(jié)inux常用的命令

發(fā)布時間:2021-09-28 10:26:21 來源:億速云 閱讀:92 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要講解了“inux常用命令總結(jié)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“inux常用命令總結(jié)”吧!

linux文件中存在^M
使用shell命令tr可以實現(xiàn)去除,具體命令如下:

代碼如下:

  cat -v yourfile | tr -d "^M" > targetfile

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 恢復(fù)ctrl+u上次執(zhí)行時刪除的字符
1.7 ctrl + ? 撤消前一次輸入
1.8 alt + r 撤消前一次動作
1.9 alt + d 刪除光標所在位置的后單詞
2.移動
2.1 ctrl + a 將光標移動到命令行開頭相當于VIM里shift+^
2.2 ctrl + e 將光標移動到命令行結(jié)尾處相當于VIM里shift+$
2.3 ctrl + f 光標向后移動一個字符相當于VIM里l
2.4 ctrl + b 光標向前移動一個字符相當于VIM里h
2.5 ctrl + 方向鍵左鍵 光標移動到前一個單詞開頭
2.6 ctrl + 方向鍵右鍵 光標移動到后一個單詞結(jié)尾
2.7 ctrl + x 在上次光標所在字符和當前光標所在字符之間跳轉(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

感謝各位的閱讀,以上就是“inux常用命令總結(jié)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對inux常用命令總結(jié)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI