unix 中 long-运行 `find` 命令的替代方法
alternatives to long-running `find` command in unix
我想删除超过 7 天的文件,我正在使用此命令来执行此操作:
find /directory -mtime +7 -exec rm -f {} \;
它工作正常,但需要的时间太长。有没有其他方法可以删除超过 7 天的文件,例如不使用 find
?
已知使用“-exec rm”会减慢速度。如果您的 find
有 -delete 选项,请尝试使用它,如下所示:
find /directory -type f -mtime +7 -delete
如果您的 find
没有 -delete 选项,请考虑使用 GNU find(它可能已经作为 gfind
在您的系统上可用)。
还有其他可能性,例如使用 xargs
。有关进一步的讨论和一些其他选项,请参阅 Deleting-Files。
将最后的 ;
更改为加号 +
$ find /directory -type f -mtime +7 -exec rm -f {} \+
或使用xargs
命令:
$ find /directory -type f -mtime +7 | xargs rm
两者都将至少快 3 倍
我想删除超过 7 天的文件,我正在使用此命令来执行此操作:
find /directory -mtime +7 -exec rm -f {} \;
它工作正常,但需要的时间太长。有没有其他方法可以删除超过 7 天的文件,例如不使用 find
?
已知使用“-exec rm”会减慢速度。如果您的 find
有 -delete 选项,请尝试使用它,如下所示:
find /directory -type f -mtime +7 -delete
如果您的 find
没有 -delete 选项,请考虑使用 GNU find(它可能已经作为 gfind
在您的系统上可用)。
还有其他可能性,例如使用 xargs
。有关进一步的讨论和一些其他选项,请参阅 Deleting-Files。
将最后的 ;
更改为加号 +
$ find /directory -type f -mtime +7 -exec rm -f {} \+
或使用xargs
命令:
$ find /directory -type f -mtime +7 | xargs rm
两者都将至少快 3 倍