1.按記憶體從大到小排列進程:
ps -eo "%C : %p : %z : %a"|sort -k5 -nr
2.查看當前有哪些進程;查看進程開啟的檔案:
ps -A ;lsof -p PID
3.擷取當前IP地址(從中學習grep,awk,cut的作用)
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-
4.統計每個單詞出現的頻率,並排序
awk '{arr[$1]+=1 }END{for(i in arr){print arr"\t"i}}' 檔案名稱 | sort -rn
5.顯示10條最常用的命令
sed -e "s/| /\n/g" ~/.bash_history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head
6.殺死Nginx進程(殺死某一進程)
ps -ef|grep -v grep |grep nginx|awk '{print $2}' 或
for i in `ps aux | grep nginx | grep -v grep | awk {'print $2'}` ; do kill $i; done
7.列出當前檔案夾目錄大小,以G,M,K顯示。
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf"%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"):$1>=2**10? ($1/2**10, "K"): ($1, "")}e'
shaw答案 :du -hs $(du -sk ./`ls -F |grep /` |sort -nr |awk '{print $NF}')
也可 以實現,不過不是特別完美。但好記。
8.清空linux buffer cache
sync && echo 3 > /proc/sys/vm/drop_caches
9.將目前的目錄檔案名稱全部轉換成小寫
for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
10.消除vim中的^M的幾種方法
1)dos2uninx filename
2)sed -e 's/^M//' filename
3)vim中 :s/^M//gc
4)col -bx < dosfile > newfile
5)tr -s "\r\n" "\n" < file > newfile
11. 清除所有arp緩衝
arp -n|awk '/^[1-9]/ {print "arp -d "$1}'|sh
12. 綁定已知機器的arp地址
cat /proc/net/arp | awk '{print $1 " " $4}' |sort -t. -n +3 -4 > /etc/ethers
13. perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf
14、不允許某個使用者使用rm命令
[root@localhost pp]# setfacl -m u:pp:000 /bin/rm
[root@localhost pp]# su - pp
[pp@localhost ~]$ mkdir test
[pp@localhost ~]$ rm -rf test/
-bash: /bin/rm: 許可權不夠
修改回來命令
[pp@localhost ~]$ su root
口令:
[root@localhost pp]# setfacl -m u:pp:rwx /bin/rm
[root@localhost pp]# su - pp
[pp@localhost ~]$ rm -rf test/
[pp@localhost ~]$
15、打包排除目錄使用
tar zcvf family.tar.gz ./family/* --exclude=./family/1/ss/attachments --exclude=./family/1/ss/bbs/attachments
16、linux下使用命令列模式上傳檔案夾
ncftpput -R -u user -p 'passwd' -P 21 192.168.1.1 /home/test/ /root/test(原本地目錄)
4、查看佔用記憶體最多的前15個程式
ps -aux|awk '{print $4"\t"$11}'|grep -v MEM|sort -r|uniq -c |head -15
ps (shift+M查看佔用記憶體,shift+p查看cpu)