分享平時工作中那些給力的shell命令

來源:互聯網
上載者:User

1.顯示消耗記憶體/CPU最多的10個進程ps aux | sort -nk +4 | tailps aux | sort -nk +3 | tail——————————————————————————————————————————2.查看Apache的並發請求數及其TCP串連狀態netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’——————————————————————————————————————————3.找出自己最常用的10條命令及使用次數(或求訪問最多的ip數)sed -e ‘s/| //n/g’ ~/.bash_history |cut -d ‘ ‘ -f 1 | sort | uniq -c | sort -nr | head——————————————————————————————————————————4.日誌中第10個欄位表示連線時間,求平均連線時間cat access_log |grep “connect cbp” |awk ‘BEGIN{sum=0;count=0;}{sum+=$10;count++;}END{printf(“sum=%d,count=%d,avg=%f/n”,sum,count,sum/count)}’——————————————————————————————————————————5.lsof命令lsof abc.txt 顯示開啟檔案abc.txt的進程lsof -i :22 知道22連接埠現在運行什麼程式lsof -c abc 顯示abc進程現在開啟的檔案lsof -p 12  看進程號為12的進程開啟了哪些檔案——————————————————————————————————————————6.殺掉一個程式的所有進程pkill -9 httpdkillall -9 httpd注意盡量不用-9,資料庫伺服器上更不能輕易用kill,否則造成重要資料丟失後果將不堪設想。——————————————————————————————————————————7.rsync命令(要求只同步某天的壓縮檔,而且遠程目錄保持與本地目錄一致)/usr/bin/rsync -azvR –password-file=/etc/rsync.secrets `find . -name “*$yesterday.gz”  -type f ` storage@192.168.2.23::logbackup/13.21/——————————————————————————————————————————8.把目錄下*.sh檔案改名為*.SHfind .  -name “*.sh” | sed  ’s//(.*/)/.sh/mv /0 /1.SH/’ |shfind .  -name “*.sh” | sed  ’s//(.*/)/.sh/mv & /1.SH/’|sh  (跟上面那個效果一樣)——————————————————————————————————————————9.ssh執行遠端程式,並在本地顯示ssh -n -l zouyunhao 192.168.2.14 “ls -al /home/zouyunhao”——————————————————————————————————————————10. 直接用命令列修改密碼echo “zouyunhaoPassword” |passwd –stdin zouyunhao——————————————————————————————————————————ssh-keygenssh-copy-id -i ~/.ssh/id_rsa.pub user@remoteServer——————————————————————————————————————————12.以http方式共用當前檔案夾的檔案$ python -m SimpleHTTPServer在瀏覽器訪問http://IP:8000/即可下載目前的目錄的檔案。——————————————————————————————————————————13.shell段注釋:<<’echo hello,world!’——————————————————————————————————————————14.查看伺服器序號dmidecode |grep “Serial Number”   (查看機器其他硬體資訊也可用這個命令)——————————————————————————————————————————15.查看網卡是否有網線物理串連/sbin/mii-tool——————————————————————————————————————————16.查看linux系統或者mysql錯誤碼錶示的意思,如查看13錯誤碼錶示的意思:perror  13——————————————————————————————————————————17.關於cpu個數
查看邏輯cpu個數:cat /proc/cpuinfo | grep “processor” | wc -l
查看物理cpu個數:cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l
查看每個物理cpu的核心數cores:cat /proc/cpuinfo | grep “cpu cores” | wc -l
如果所有物理cpu的cores個數加起來小於邏輯cpu的個數,則該cpu使用了超執行緒技術。查看每個物理cpu中邏輯cpu的個數:cat /proc/cpuinfo | grep “siblings”——————————————————————————————————————————(不斷更新中……)本文出自孤風顛影|網站營運 網址:http://yunhaozou.org/perl-shell/162.html.轉載請保留.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.