如何删除所有超过3天的文件,当“参数列表太长”? [英] How to delete all files older than 3 days when "Argument list too long"?

查看:207
本文介绍了如何删除所有超过3天的文件,当“参数列表太长”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有82000个文件和目录的日志文件目录(大约一半)。

我需要删除所有的文件和目录这是超过3天。



在一个有37000个文件的目录中,我可以这样做:

  find * -mtime +3 -exec rm {} \; 

但是有82000个文件/目录,我得到错误:


/ usr / bin / find:参数列表太长

如何解决此错误,以便我可以删除所有超过3天的文件/目录? 解决方案

删除目录中的所有文件: >找到。 -mtime +3 | xargs rm -Rf

或者,更符合OP的原始命令:

  find。 -mtime +3 -exec rm -Rf  -  {} \; 


I've got a log file directory that has 82000 files and directories in it (about half and half).

I need to delete all the file and directories which are older than 3 days.

In a directory that has 37000 files in it, I was able to do this with:

find * -mtime +3 -exec rm {} \;

But with 82000 files/directories, I get the error:

/usr/bin/find: Argument list too long

How can I get around this error so that I can delete all files/directories that are older than 3 days?

解决方案

To delete all files and directories within the current directory:

find . -mtime +3 | xargs rm -Rf

Or alternatively, more in line with the OP's original command:

find . -mtime +3 -exec rm -Rf -- {} \;

这篇关于如何删除所有超过3天的文件,当“参数列表太长”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆