sed -i 's@^DBHost=.*@DBHost=127.0.0.1@' filename 以DBHost=.开头的行,后面替换成127.0.0.1
egrep -v "[[:space:]]*#|^$" /etc/ntp.conf filename 删除以#开头和空行
for i in `ls`;do echo "mv $i $i" |sed 's/_bak$//e' ;done 批量删除文件后缀名
for i in `ls`;do mv $i ${i}_bak;done 批量添加文件后缀
sed -i 's/password_hash/password_hash_custom/g' `grep -rl "password_hash" .` 批量替换文件内容(包括递归下去的文件)
grep -nr "http" / 搜索/下所有包含http的文件
sed -i '/PermitRoot/s/^#//' /etc/ssh/sshd_config 删除匹配到PermitRoot的行,并且把前面的#删除
find . -type f -exec sed -i 's/\xEF\xBB\xBF//' {} \; 清除bom头
find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} \;
awk
'{a[b[$1]++]}END{for(i=length(a);i>0;i--)for(j in b)if(b[j]==i){c++;if(c<=10)print j,i}}'
access.log 格式化输入日志ip访问量
cat access.log| sed -n '/22\/Jun\/2017:16:20/,/22\/Jun\/2017:16:30/p' 按时间查看nginx访问
本文转自 转身撞墙角 51CTO博客,原文链接:http://blog.51cto.com/chentianwang/1719087