1.顯示消耗內(nèi)存/CPU最多的10個進(jìn)程
ps aux | sort -nk +4 | tail
ps aux | sort -nk +3 | tail
——————————————————————————————————————————
2.查看Apache的并發(fā)請求數(shù)及其TCP連接狀態(tài)
netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
——————————————————————————————————————————
3.找出自己最常用的10條命令及使用次數(shù)(或求訪問最多的ip數(shù))
sed -e ‘s/| / /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 ”,sum,count,
sum/count)}’
——————————————————————————————————————————
5.lsof命令
lsof abc.txt 顯示開啟文件abc.txt的進(jìn)程
lsof -i :22 知道22端口現(xiàn)在運行什么程序
lsof -c abc 顯示abc進(jìn)程現(xiàn)在打開的文件
lsof -p 12 看進(jìn)程號為12的進(jìn)程打開了哪些文件
——————————————————————————————————————————
6.殺掉一個程序的所有進(jìn)程
pkill -9 httpd
killall -9 httpd
注意盡量不用-9,數(shù)據(jù)庫服務(wù)器上更不能輕易用kill,否則造成重要數(shù)據(jù)丟失后果將不堪設(shè)想。
——————————————————————————————————————————
7.rsync命令(要求只同步某天的壓縮文件,而且遠(yuǎn)程目錄保持與本地目錄一致)
/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文件改名為*.SH
find . -name “*.sh” | sed ’s/\(.*\)\.sh/mv \0 \1.SH/’ |sh
find . -name “*.sh” | sed ’s/\(.*\)\.sh/mv & \1.SH/’|sh (跟上面那個效果一樣)
——————————————————————————————————————————
9.ssh執(zhí)行遠(yuǎn)程的程序,并在本地顯示
ssh -n -l zouyunhao 192.168.2.14 “ls -al /home/zouyunhao”
——————————————————————————————————————————
10. 直接用命令行修改密碼
echo “zouyunhaoPassword” |passwd –stdin zouyunhao
——————————————————————————————————————————
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remoteServer
——————————————————————————————————————————
12.以http方式共享當(dāng)前文件夾的文件
$ python -m SimpleHTTPServer
在瀏覽器訪問http://IP:8000/即可下載當(dāng)前目錄的文件。
——————————————————————————————————————————
13.shell段注釋
:《’echo hello,world!’
——————————————————————————————————————————
14.查看服務(wù)器序列號
dmidecode |grep “Serial Number” (查看機器其他硬件信息也可用這個命令)
——————————————————————————————————————————
15.查看網(wǎng)卡是否有網(wǎng)線物理連接
/sbin/mii-tool
——————————————————————————————————————————
16.查看linux系統(tǒng)或者mysql錯誤碼表示的意思,如查看13錯誤碼表示的意思:
perror 13
——————————————————————————————————————————
17.關(guān)于cpu個數(shù)
查看邏輯cpu個數(shù):cat /proc/cpuinfo | grep “processor” | wc -l
查看物理cpu個數(shù):cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l
查看每個物理cpu的核數(shù)cores:cat /proc/cpuinfo | grep “cpu cores”
如果所有物理cpu的cores個數(shù)加起來小于邏輯cpu的個數(shù),則該cpu使用了超線程技術(shù)。查看每個物理cpu中邏輯cpu的個數(shù):cat /proc/cpuinfo | grep “siblings”
——————————————————————————————————————————
18.從格式不規(guī)范的日志中截取字符串
perl -ne ’print “$1 ” if /servletPath=(\S+)/g’ test.log
億恩科技地址(ADD):鄭州市黃河路129號天一大廈608室 郵編(ZIP):450008 傳真(FAX):0371-60123888
聯(lián)系:億恩小凡
QQ:89317007
電話:0371-63322206 本文出自:億恩科技【www.allwellnessguide.com】
服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|