bash 查找 -mtime 早于 1 小时的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/543946/
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
find -mtime files older than 1 hour
提问by Abs
I have this command that I run every 24 hours currently.
我有这个命令,目前每 24 小时运行一次。
find /var/www/html/audio -daystart -maxdepth 1 -mtime +1 -type f -name "*.mp3" -exec rm -f {} \;
I would like to run it every 1 hour and delete files that are older than 1 hour. Is this correct:
我想每 1 小时运行一次并删除超过 1 小时的文件。这样对吗:
find /var/www/html/audio -daystart -maxdepth 1 -mtime **+0.04** -type f -name "*.mp3" -exec rm -f {} \;
I am not sure of my use of the decimal number??
我不确定我使用的十进制数??
Thanks for any corrections.
感谢您的任何更正。
EDIT
编辑
OR could I just use -mmin 60? Is this correct?
或者我可以只使用-mmin 60吗?这样对吗?
EDIT2
编辑2
I tried your test, good thing you suggested it. I got an empty result. I want all files OLDERthan 60mins to be deleted! How can I do this?? Does my command actually do this?
我试过你的测试,还好你建议了。我得到了一个空的结果。我希望所有的文件较旧超过60分钟将被删除!我怎样才能做到这一点??我的命令真的做到了吗?
回答by Sean Bright
What about -mmin
?
怎么样-mmin
?
find /var/www/html/audio -daystart -maxdepth 1 -mmin +59 -type f -name "*.mp3" \
-exec rm -f {} \;
From man find:
从 man 中找到:
-mmin n File's data was last modified n minutes ago.
Also, make sure to test this first!
另外,一定要先测试这个!
... -exec echo rm -f '{}' \; ^^^^ Add the 'echo' so you just see the commands that are going to get run instead of actual trying them first.