概述
过滤:inet addr:192.168.128.130 Bcast:192.168.128.255 Mask:255.255.255.0(要求:只剩下192.168.128.130 192.168.128.255 255.255.255.0) awk -F "[ :]+" '{print $4,$6,$8}' 1.txt(1.txt为存放过滤内容的文件)
用awk将2.txt文件中的第10到20行的第三列重定向到/tmp/1.txt中:awk -F ":" 'NR > 9 && NR < 21 {print $3}' 2.txt > 1.txt
使用rm删除时,做如下提示且永久生效:rm -f [文件名] Do not use rm command
方法如下:echo "alias rm = 'echo Do not use rm ' " >> /etc/bashrc /etc/profile
查找文件名不为1.txt的文件:find /tmp -type f ! -name "1.txt"
打印/etc/passwd 文件中的2-5行(1)head -5 /etc/passwd | tail -4(2)sed -n '2,5p' /etc/passwd(3)awk 'NR >1 && NR <6' /etc/passwd
打印/etc/passwd 中一行内容 :awk 'NR ==1{print $0}' /etc/passwd $0:表示输出一整行
将一行中第一列与第七列对换:awk -F ":" 'NR ==1{print $7":"$2":".......$1}' /etc/passwd
查找/tmp下所有7天以前以log结尾的大于1M的文件移动到/tmp/1下:find /tmp -type f -name "*.log" -size +1M -mtime +7 -exec mv {} tmp1 ;
压缩包解压:tar -zxvf 1.tar.gz tar -zxvf 1.tar.gz -C [解压到的目录名]
将1目录下的文件进行压缩:tar -zcvf 1.tar.gz /1
找出以d开头的:ls -l | grep "^d"
ls -lrt /etc:执行这个命令后最新的文件会在最下面
过滤3306端口,使其带颜色:grep --color =auto 3306 /etc/services
删除七天以前日志的三种方法:(1)find /app/logs/ -type f -mtime +7 | xargs rm -f(2)find /app/logs -type f -mtime +7 -exec rm -f {} ;(3)rm -f `find /app/logs/ -type f -mtime +7`
实时查看系统日志:tail -f /var/log/messages
查看行号:(1)nl nginx.conf(空行不记录行号)(2)cat -n nginx.conf(空行记录行号)(3)less -N nginx.conf(4)awk '{print NR ,$0}' nignx.conf(5)grep -n . nginx.conf(过滤掉空行)(6)grep -n ".*" nginx.conf(不过滤掉空行)
最后
以上就是开放超短裙为你收集整理的Linux中awk、sed、xargs等命令的学习的全部内容,希望文章能够帮你解决Linux中awk、sed、xargs等命令的学习所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复