首页 > 系统服务 > 详细

Linux题目-2

时间:2018-08-05 21:22:14      阅读:173      评论:0      收藏:0      [点我收藏+]


【删除15天以前的日志文件】

试验环境模拟:

for n in `seq 30`;

do date -s "2018-07-$n";

touch access_xwj_$(date +%F).log;  ——注意: date 和 + 之间有空格

done


脚本的意义:创建20180701~20180730号的日志文件

技术分享图片

技术分享图片


三种删除方式

1、[root@xwj ~]# find /xwj/log -type f -mtime +15 -exec rm -f {} \;

2、[root@xwj ~]# find /xwj/log -type f -mtime +15 | xargs rm -f 

3、[root@xwj ~]# rm -f `find /xwj/log -type f -mtime +15`

技术分享图片





【调试系统服务时,希望实时看到日志文件的变化 /var/log/messages】

tail -f   output  appended  data  as  the  file  grows; -f,

            --follow, and --follow=descriptor are equivalent


[root@xwj ~]# tail -f /var/log/messages 

技术分享图片





【打印配置文件,显示行号】

生成实验环境

技术分享图片

技术分享图片


方法一:

[root@xwj ~]# cat -n xwj.txt  (空行也显示行号)

技术分享图片


方法二:

[root@xwj ~]# grep -n . xwj.txt (点代表任意一个字符)

技术分享图片


方法三:

vi 编辑器 

命令模式 :set nu 

技术分享图片


方法四:

[root@xwj ~]# awk '{print NR,$0}' xwj.txt    (NR代表行号,$0代表每一行)

技术分享图片


方法五:

[root@xwj ~]# less -N xwj.txt 

技术分享图片



Linux题目-2

原文:http://blog.51cto.com/11193863/2154993

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!