|  
   1.顯示消耗內存/CPU最多的10個進程 
  ps aux | sort -nk +4 | tail 
  ps 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/| / /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的進程 
  lsof -i :22 知道22端口現在運行什么程序 
  lsof -c abc 顯示abc進程現在打開的文件 
  lsof -p 12  看進程號為12的進程打開了哪些文件 
  —————————————————————————————————————————— 
  6.殺掉一個程序的所有進程 
  pkill -9 httpd 
  killall -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文件改名為*.SH 
  find .  -name “*.sh” | sed  ’s/\(.*\)\.sh/mv \0 \1.SH/’ |sh 
  find .  -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-keygen 
  ssh-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” 
  如果所有物理cpu的cores個數加起來小于邏輯cpu的個數,則該cpu使用了超線程技術。查看每個物理cpu中邏輯cpu的個數:cat /proc/cpuinfo | grep “siblings” 
  —————————————————————————————————————————— 
  18.從格式不規范的日志中截取字符串 
  perl  -ne  ’print “$1 ” if  /servletPath=(\S+)/g’  test.log 
億恩科技地址(ADD):鄭州市黃河路129號天一大廈608室 郵編(ZIP):450008 傳真(FAX):0371-60123888 
   聯系:億恩小凡 
   QQ:89317007 
   電話:0371-63322206  本文出自:億恩科技【www.endtimedelusion.com】 
      
      
		服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM] 
       |