五年屌絲營運工作shell精華

來源:互聯網
上載者:User

標籤:五年屌絲營運工作shell精華

屌絲營運常用shell
列出你最常用的10條shell
history | awk ‘{a[$2]++}END{for(i in a){print a[i] " " i}}‘ | sort -rn | head
history | awk ‘{a[$4]++}END{for(i in a){print a[$i] " " i}}‘ | sort -rn | head
grep -v "#" .bash_history |awk ‘{++a[$1]}END{for(i in a)print i,a[i]|"sort -k2 -nr"}‘  | head
網路連接數目
netstat -an | grep -E "^(tcp)" | cut -c 68- | sort | uniq -c | sort -n     #查看狀態數串連數
netstat -ntu | awk ‘{print $5"\n"}‘ | cut -d: -f1 | sort | uniq -c | sort -nr|head -n 20 #統計IP串連數
netstat -an -t | grep ":22" | grep ESTABLISHED | awk ‘{printf "%s %s\n",$5,$6}‘ | sort | wc -l #進程串連數
取網卡IP
/sbin/ifconfig |sed ‘s/.*inet addr:\(.*\) Bca.*/\1/g‘ |sed -n ‘/br/{n;p}‘ #雙網卡綁定用這個
/sbin/ifconfig |sed ‘s/.*inet addr:\(.*\) Bca.*/\1/g‘ |sed -n ‘/eth/{n;p}‘ #普通網卡用這個
ifconfig eth0 |grep "inet addr:" |awk ‘{print $2}‘|cut -c 6-  或者
ifconfig | grep ‘inet addr:‘| grep -v ‘127.0.0.1‘ | cut -d: -f2 | awk ‘{ print $1}‘
系統資訊統計
dmidecode -t system |grep -E ‘Serial‘|awk -F‘:‘ ‘{print $2}‘ (系統序號查詢)
cat /proc/cpuinfo  | grep CPU | awk  -F: ‘{print $2}‘ |  sort|uniq -c (cpu核心數)
dmidecode -t system |grep ‘Product‘|awk ‘{print $3$4}‘  (單板裝置類型)
dmidecode | grep -P -A 5 ‘Memory Device‘ | grep Size | grep -v Range|grep -i -v "no module"|sed -r ‘s/^\s+//g‘ | sort|uniq -c (記憶體大小)
echo `/sbin/ifconfig |sed ‘s/.*inet addr:\(.*\) Bca.*/\1/g‘ |sed -n ‘/eth/{n;p}‘ ` `hostname` >>/etc/hosts 取IP和主機名稱定向到/etc/hostname  
系統抓包分析
tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts  (tcpdump 抓包 ,用來防止80連接埠被人攻擊時可以分析資料 )
less | awk ‘ {printf $3"\n"}‘ | cut -d. -f 1-4 | sort | uniq -c | awk ‘{printf $1" "$2"\n"}‘ | sort -n -t\   +0 (然後檢查IP的重複數 並從小到大排序 注意 "-t\ +0" 中間是兩個空格 )
系統進程管理
ps -eo pid,lstart,etime | grep 26871 (進程已耗用時間)
lsof -p 10412 (查看進程開啟的檔案 10412是進程的PID)
ps -e -o "%C : %p : %z : %a"|sort -k5 -nr  (查看進程 按記憶體從大到小排列 )
 ps -e -o "%C : %p : %z : %a"|sort -nr     (按cpu利用率從大到小排列)
ps aux |grep mysql |grep -v grep |awk ‘{print $2}‘ |xargs kill -9  (殺掉mysql進程)
killall -TERM mysqld  殺掉mysql進程:
ps -eal | awk ‘{ if ($2 == "Z") {print $4}}‘ | kill -9 殺掉僵死進程
網卡流量
dstat -acdgilmnprstTfy (centos查看網卡流量)
iftop   (suse系統網卡流量)
sar -n DEV 1 10 (suse系統網卡流量)
iotop -o (查看那個進程最磨磁碟)
檔案管理
刪除0位元組檔案
find -type f -size 0 -exec rm -rf {} \;
查看目錄下10個大檔案
du -cks * | sort -rn | head -n 10
du -h --max-depth=1  /home
用三種方法將兩列合并成一行
cat test
192.168.110.171
00:1F:D0:D4:DD:47
xargs -n 2 < test
sed ‘N;s/\n/ /‘ test
awk -v ORS="" ‘{printf $0" "}NR%2==0{print "\n"}‘ 1 test
192.168.110.171 00:1F:D0:D4:DD:47

本文出自 “呂布天下” 部落格,請務必保留此出處http://2364821.blog.51cto.com/2354821/1434094

相關文章

聯繫我們

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