Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在linux中删除1天以前的文件_Linux_Bash_Shell_Unix_Centos - Fatal编程技术网

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

如何在linux中删除1天以前的文件,linux,bash,shell,unix,centos,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

我看到了许多在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远程服务器删除旧文件,并将我的问题发布在这里

更新:
我尝试了答案,但还是没有成功

[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]# 
请告诉我如何修理它。期待中的感谢

试试:

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

如果指定
ls
而不是
rm
,您是否看到列出的文件?投票支持
ls
idea而不是
rm
投票支持
ls
idea而不是
rm
,很酷,那么您得到了什么结果?是否需要(您看到了要删除的文件名)?我刚试过
查找-mtime+1-execrm-Rf--{}它对我来说很好。我的坏。我错误地使用了rm-rf*.dmp并删除了所有文件。现在至少要等一天再检查它不要把
-rf
作为一个选项,它是不需要的,可以保存数据以防出错。为什么要删除文件?如果OP只想删除文件,我会添加
-type f
,以确保它不会删除目录。@Marki555-我添加了
-type
建议,因为我认为这是个好主意。OP从未提及任何关于递归和强制删除的内容,但示例表明它正在使用,尽管是与
-R
一起使用。因此,我根据从OP示例中收集到的信息保留了
-rf
。谢谢。但是问题的标题确实暗示OP对文件感兴趣,而不是目录。@EJK-是的,它感兴趣。不久前,为了回应@Marki555的评论,我添加了
-type
选项。谢谢。@tale852150我更新了我的问题并复制了您命令的粘贴输出。你可以看到它不起作用。