1.显示消耗内存/CPU最多的10个进程
ps aux | sort -nk +4 | tail
ps aux | sort -nk +3 | tail
</div>
2.查看进程
按内存从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -k5 -nr
</div>
3.按cpu利用率从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -nr
</div>
3.查看Apache的并发请求数及其TCP连接状态
netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
</div>
4. 查找占用磁盘IO最多的进程
wget -c http://linux.web.psi.ch/dist/scientific/5/gfa/all/dstat-0.6.7-1.rf.noarch.rpm
dstat -M topio -d -M topbio
</div>
5.找出自己最常用的10条命令及使用次数(或求访问最多的ip数)
sed -e ‘s/| /\n/g' ~/.bash_history |cut -d ‘ ‘ -f 1 | sort | uniq -c | sort -nr | head
</div>
6.日志中第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)}'
</div>
7.lsof命令
lsof abc.txt 显示开启文件abc.txt的进程
lsof -i :22 知道22端口现在运行什么程序
lsof -c abc 显示abc进程现在打开的文件
lsof -p 12 看进程号为12的进程打开了哪些文件
8.rsync命令(要求只同步某天的压缩文件,而且远程目录保持与本地目录一致)
/usr/bin/rsync -azvR –password-file=/etc/rsync.secrets `find . -name “*$yesterday.gz” -type f ` storage@192.168.2.23::logbackup/13.21/
</div>
9.把目录下*.sh文件改名为*.SH
find . -name “*.sh” | sed 's/\(.*\)\.sh/mv \0 \1.SH/' |sh
find . -name “*.sh” | sed 's/\(.*\)\.sh/mv & \1.SH/'|sh (跟上面那个效果一样)
</div>
10.ssh执行远程的程序,并在本地显示
ssh -n -l zouyunhao 192.168.2.14 “ls -al /home/zouyunhao”
</div>
11.shell段注释
:<<'echo hello,world!'
</div>
12.查看网卡是否有网线物理连接
/sbin/mii-tool
</div>
13.查看linux系统或者mysql错误码表示的意思,如查看13错误码表示的意思:
perror 13
</div>
14.删除0字节文件
find -type f -size 0 -exec rm -rf {} \;
</div>
15.1.如何杀掉mysql进程:
ps aux|grep mysql|grep -v grep|awk '{print $2}'|xargs kill -9
(从中了解到awk的用途)
pgrep mysql |xargs kill -9
killall -TERM mysqld
kill -9 `cat /usr/local/apache2/logs/httpd.pid`
试试查杀进程PID
</div>
16.显示运行3级别开启的服务:
ls /etc/rc3.d/S* |cut -c 15-
(从中了解到cut的用途,截取数据)
</div>
17.如何在编写SHELL显示多个信息,用EOF
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
</div>
18. 取IP地址:
ifconfig eth0|sed -n '2p'|awk '{print $2}'|cut -c 6-30
或者:
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}'
或者:
ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'
Perl实现获取IP的方法:
ifconfig -a | perl -ne 'if ( m/^\s*inet (?:addr:)?([\d.]+).*?cast/ ) { print qq($1\n); exit 0; }'
</div>
19.内存的大小:
代码如下:</div>

