如何在linux中删除1天的文件

时间:2016-07-13 15:02:34

标签: linux bash shell unix centos

我在Linux中看到了许多删除n天旧文件的例子,但没有一个能为我工作。以下是我使用的一些命令

[root@centos dmp]# find . -mtime +1 -exec rm -Rf -- {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . -name "*.dmp*" -ctime +1 -exec rm {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# echo find . * -type f -mtime +1 -exec rm {} \;
find . GSW-11-07-2016.dmp GSW-12-07-2016.dmp GSW-13-07-2016.dmp MI-11-07-2016.dmp MI-12-07-2016.dmp MI-13-07-2016.dmp -type f -mtime +1 -exec rm {} ;
[root@centos dmp]# find . * -type f -mtime +1 -exec rm {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . * -mtime +1 -exec rm {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . * -type f -mtime +1 -exec rm {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . * -mtime +1 -exec rm -Rf -- {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . -type f -mtime +1 -name '*.dmp' -execdir rm -- {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . -type f -ctime +1 -name '*.dmp' -execdir rm -- {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp
[root@centos dmp]# find . -type f -mtime +1 -name '*.dmp' -print0 | xargs -r0 rm --
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 11 21:01 GSW-11-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 12 02:30 GSW-12-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 13 02:30 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp

2)我也在尝试从ftp远程服务器删除旧文件并在此处发布我的问题https://stackoverflow.com/questions/38309645/linux-script-to-delete-ndays-old-ftp-files

更新
我尝试了答案,但仍然没有运气

[root@centos dmp]# find . -type f -mtime +1 -exec rm -rf {} \;
[root@centos dmp]# ll
total 3259164
-rw-r----- 1 oracle dba   12754944 Jul 13 17:16 GSW-13-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 14 02:30 GSW-14-07-2016.dmp
-rw-r----- 1 oracle dba   12754944 Jul 15 02:30 GSW-15-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 13 17:16 MI-13-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 14 02:30 MI-14-07-2016.dmp
-rw-r----- 1 oracle dba 1099702272 Jul 15 02:30 MI-15-07-2016.dmp
[root@centos dmp]# 

请告知我该如何解决。在期待中感谢

1 个答案:

答案 0 :(得分:0)

尝试:

find . -type f -mtime +1 -exec rm -rf {} \;