您的位置:首页 > 运维架构 > Linux

很实用的linux运维常用命令及知识!

2012-04-03 15:34 603 查看
在Linux运维中,记录工作中的点滴,日积月累,不断提高!日常shell操作,日常经典命令集合!
1、查找所有tar文件然后移动到目录:find . -name “*.tar” -exec mv {} ./backup/ ;

2、查找for i in `find . -name *.html|sed ‘s/.//g’|sed ‘s/html/.html/g’` ;do echo http://192.168.0.170:8017$i ; done

3、去掉行首的.字符:

find . -name *.html|sed ‘s/^.//g’
4、查找类型属于文件的,然后备份到其他目录:
find . -name nginx.conf.tgz -exec cp {} dir/ ;
5、监控linux磁盘分区,如果空间大于90%,发送邮件给Linux SA

(1)、打印根分区大小

df -h |sed -n ‘//$/p’|awk ‘{print $5}’|awk -F”%” ‘{print $1}’

(2)、if条件判断该大小是否大于90,如果大于90则发送邮件报警
while sleep 5m

do
for i in `df -h |sed -n ‘//$/p’ |awk ‘{print $5}’ |sed ‘s/%//g’`

do

echo $i
if [ $i -gt 90 ];then

echo “More than 90% Linux of disk space ,Please Linux SA Check Linux Disk !” |mail -s “Warn Linux / Parts is $i%”
wugk@map.com

fi

done

done
6、统计apache访问日志,访问量排在前20 ip地址:
cat access.log |awk ‘{print $1}’|sort|uniq -c |sort -nr |head -20
7、在所有行前添加http://img.map.com,并在最后添加/

sed -e ‘s/^/http://img.map.com/maplite/map/subway/1.1//’ -e ‘s/$///’ a.txt

8、找到当前行,然后在修改该行后面的参数:

sed -i ‘/SELINUX/s/disabled/enforcing/’ /etc/selinux/config

9、查找并修改目录下所有文件夹的名字:

find . -name “NaviInfo.2010.12.0″ |xargs rename NaviInfo.2010.12.0 NaviInfo.2010.12.1

10、查看apache并发连接数,及相关转发状态:

netstat -n |awk ‘/^tcp/’|awk ‘{print $NF}’|sort |uniq -c |sort -nr

netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’

11、打印出一个文件里面最大和最小值:

cat a.txt |sort -nr|awk ‘{}END{print} NR==1′

cat a.txt |sort -nr |awk ‘END{print} NR==1′

这个才是真正的打印最大最小值:sed ‘s/ / /g’ a.txt |sort -nr|sed -n ’1p;$p’
12、使用snmpd抓取版本为v2的cacti数据方式:

snmpwalk -v2c -c public 192.168.0.241

13、修改文本中以jk结尾的替换成yz:

sed -e ‘s/jk$/yz/g’ b.txt

14、网络抓包:tcpdump

tcpdump -nn host 192.168.56.7 and port 80 抓取56.7通过80请求的数据包。

tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 80 排除0.22 80端口!

tcp/ip 7层协议 物理层–数据链路层-网络层-传输层-会话层-表示层-应用层。
15、H3C配置团体名配置:首先设置snmp版本如下:

snmp-agent sys-info version v1 v2c ,然后设置团体名:snmp-agent community read public

16、显示最常用的20条命令:

cat .bash_history |grep -v ^# |awk ‘{print $1}’ |sort |uniq -c |sort -nr |head -20
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息