教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 shell命令按照时间删除文件

shell命令按照时间删除文件

发布时间:2014-08-27   编辑:jiaochengji.com
其实,就是find命令的应用,主要用到了参数-mtime而已。

其实,就是find命令的应用,主要用到了参数-mtime而已。
供初学者参考。

复制代码 代码如下:
[root@localhost audit]# ll
总用量 14788
-rw------- 1 root root 4632650 10月 19 09:12 audit.log
-r-------- 1 root root 5243056 10月 16 18:32 audit.log.1
-r-------- 1 root root 5242984 10月 13 19:33 audit.log.2

[root@localhost audit]# find . -mtime +7 -exec rm -rf {} \;

[root@localhost audit]# ll
总用量 14788
-rw------- 1 root root 4632650 10月 19 09:12 audit.log
-r-------- 1 root root 5243056 10月 16 18:32 audit.log.1
-r-------- 1 root root 5242984 10月 13 19:33 audit.log.2

[root@localhost audit]# find . -mtime +4 -exec rm -rf {} \;

[root@localhost audit]# ll
总用量 9660
-rw------- 1 root root 4632650 10月 19 09:12 audit.log
-r-------- 1 root root 5243056 10月 16 18:32 audit.log.1
[root@localhost audit]#

您可能感兴趣的文章:
用shell脚本找出文件中包含指定字段的文件(图文)
shell 中 &&和
shell命令按照时间删除文件
shell内部命令使用详解
Linux下自动清理日志的shell脚本
shell编程基础之认识与学习BASH
shell中sort、uniq、cut、paste和split用法详解
inux shell初级入门教程
Linux(centos)下安装卸载命令rpm make install
python脚本如何测试手机

[关闭]
~ ~