Linux Shell常用命令手冊(Updating)

來源:互聯網
上載者:User

標籤:

  • 檢查遠程連接埠是否對bash開放:

nc -nvv  $IP $PORTtelnet $IP $PORT

 

  • 當前任務的前後台切換:

Ctrl + zfg

 

  • 截取變數前5個字元:

${variable:0:5}

  • SSH debug 模式:
ssh -vvv [email protected]_addressSSH with pem key:ssh [email protected]_address -i key.pem

 

  • 監視記錄檔
tail -f $FILE_NAME

 

多個監視的指令碼

multi_tail:

#!/bin/shfunction clean(){  #echo [email protected];  #for file in "[email protected]"; do ps -ef|grep $file|grep -v grep|awk ‘{print $2}‘|xargs kill -9; done  jobs -p|xargs kill -9  }files=[email protected]# When this exits, exit all back ground process also.#trap "ps -ef|grep tail|grep -v grep|awk ‘{print "‘$2‘"}‘|xargs kill -9" EXITtrap "clean $files " EXIT# iterate through the each given file names,for file in "[email protected]"do        # show tails of each in background.        tail -f $file &done# wait .. until CTRL+Cwait
  • 用wget抓取完整的網站目錄結構,存放到本地目錄中:
wget -r --no-parent --reject "index.html*" http://hostname/ -P /home/user/dirs

 

一次建立多個目錄:

mkdir -p /home/user/{test,test1,test2}

 

列出包括子進程的進程樹:

ps axwef

 

建立 war 檔案,類似tar ball的參數解壓和壓縮:

jar -cvf name.war file

 

測試硬碟寫入速度使用dd命令:

dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img

擷取文本的md5 hash:

echo -n "text" | md5sum

 

檢查xml格式:

xmllint --noout file.xml

 

將tar.gz提取到新目錄裡:

tar zxvf package.tar.gz -C new_dir

 

使用curl擷取HTTP頭資訊:

curl -I http://www.example.com

 

修改檔案或目錄的時間戳記(YYMMDDhhmm):

touch -t 0712250000 file

 

用wget命令執行ftp下載:

wget -m ftp://username:[email protected]

 

產生隨機密碼(例子裡是16個字元長):

LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;

 

快速備份一個檔案:

cp some_file_name{,.bkp}

 

訪問Windows共用目錄:

smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir

 

執行記錄裡的命令(這裡是第100行), ksh支援類vi的翻命令的操作, bash一般支援上下翻:

!100

 

解壓和壓縮(zip壓縮原檔案就被壓進去了,不同於tar):

unzip package_name.zip -d dir_name
zip package_name.zip files

 

輸入多行文字(CTRL + d 退出, 或者指定退出字串):

cat > tt
cat > tt < EOF

 

建立空檔案或清空一個現有檔案:

:> file

 

同步時間的命令:

ntpdate your_sync_server_name

用netstat顯示所有tcp4監聽連接埠:

netstat 命令 -n 表示純數字顯示, -t表示tcp協議, -u表示udp協議, -l表示監聽

netstat -lnt4 | awk ‘{print $4}‘ | cut -f2 -d: | grep -o ‘[0-9]*‘

重複運行檔案,顯示其輸出(預設是2秒一次):

watch ps -ef

 

所有使用者列表,組使用者列表:

cat /etc/passwdcat /etc/group

 

掛載某個使用者在讀寫入模式:

mount -o remount,rw /

 

掛載一個目錄(這是不能使用連結的情況):

mount --bind /source /destination

 

動態更新DNS server:

nsupdate < <EOF update add $HOST 86400 A $IP send EOF

 

遞迴grep所有目錄,和find命令配合使用效果同:

grep -r "some_text" /path/to/dir

 

列出前10個最大的檔案:

lsof / | awk ‘{ if($7 > 1048576) print $7/1048576 "MB "$9 }‘ | sort -n -u | tail

 

顯示剩餘記憶體(MB):

如果是unix環境, 使用vmstat或者topas命令自己查看也可

free -m | grep cache | awk ‘/[0-9]/{ print $4" MB" }‘

 

 

找出/home/user下所有空子目錄:

find /home/user -maxdepth 1 -type d -empty

 

擷取test.txt檔案中第50-60行內容:

< test.txt sed -n ‘50,60p‘

在需要提升許可權的情況下往一個檔案裡追加文本:

echo "some text" | sudo tee -a /path/file

 

列出所有kill signal參數:

kill -l

 

在bash記錄裡禁止記錄最後一次會話:

kill -9 $$

 

nmap掃描網路尋找開放的連接埠:

nmap -p 8081 172.20.0.0/16

 

 

將所有檔案名稱中含有”txt”的檔案移入$HOME目錄:

find -name "*txt*" | xargs mv -v $HOME

 

將檔案按行並列顯示:

paste test.txt test1.txt

 

shell裡的進度條:

pv data.log

 

使用netcat將資料發送到Graphite server:

echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000

 

將tabs轉換成空格:

expand test.txt > test1.txt

 

Skip bash history:

< space >cmd

 

去之前的工作目錄:

cd -

 

拆分大體積的tar.gz檔案(每個100MB),然後合并回去:

split –b 100m /path/to/large/archive /path/to/output/files cat files* > archive

 

使用curl擷取HTTP status code:

curl -sL -w "%{http_code}\\n" www.example.com -o /dev/null

當Ctrl + c不好使時:

Ctrl + \

 

擷取檔案owner:

stat -c %U file.txt

 

block裝置列表:

lsblk -f

 

找出檔案名稱結尾有空格的檔案:

find . -type f -exec egrep -l " +$" {} \;

 

找出檔案名稱有tab縮排符的檔案

find . -type f -exec egrep -l $‘\t‘ {} \;

 

用”=”列印出橫線:

printf ‘%100s\n‘ | tr ‘ ‘ =

 

Linux Shell常用命令手冊(Updating)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.