bash 删除目录中超过 1 天的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16680851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
delete all files within a directory that are older than 1 day
提问by stdcerr
I need to ensure that I have no old files left in my directory so what I think I do is
我需要确保我的目录中没有旧文件,所以我认为我要做的是
find . -type f -mtime +1 -delete
i got that from the find man page but then
find . -type f -mtime +1 -exec /bin/rm
我是从 find 手册页上得到的,但后来
找 。-type f -mtime +1 -exec /bin/rm
but again, now told that find: -exec requires an argument- didn't iI pass this. So I started Googling and I found that my command needs to look likee this:
但同样,现在告诉find: -exec 需要一个参数- 我没有通过这个。所以我开始谷歌搜索,我发现我的命令需要看起来像这样:
find . -type f -mtime +1 -exec /bin/rm -f {} +
and now I'm just wondering what the two {}s and the +sign are for. Can anyone help me here?
现在我只是想知道两个{}和+号是干什么用的。有人能帮我一下吗?
Thanks!
谢谢!
回答by rodrigo
The {}stands for the name of the file(s) found.
该{}代表(第)发现的文件的名称。
The +sign (instead of a ;) means that this command accepts multiple file names in the same command, so that findcan run much faster because it is run less times. The number of files added to each execution of the command is limited by the maximum length of the command line findis willing to use.
该+标志(而不是;这个命令接受相同的命令多个文件名,这样)的手段find,因为它是少跑倍运行速度会快得多。添加到每次执行命令的文件数受命令行find愿意使用的最大长度限制。

