Cron Job - 每天删除所有 .flv 文件的命令
我每天通过 cron 运行以下命令:
find /home/get/public_html/videos -daystart -maxdepth 0
-mtime +1 -type f -name "*.flv" |xargs rm -f
问题是它不会删除目录中 1 天或以上的 .flv 文件。
我怎样才能纠正上面的命令?
编辑:Paul - 命令“ls -l /home/get/public_html/videos”会生成 2000 多个文件,但其中有 2 个应该删除:
-rw-r--r-- 1 get get 3501188 Jan 4 15:24 f486cf0a2b6bb40e4c50c991785084131231104229.flv
-rw-r--r-- 1 get get 10657314 Jan 4 17:51 f5f1490ddaa11a663686f9d06fb37d981231112941.flv
I have this command that I run everyday via cron:
find /home/get/public_html/videos -daystart -maxdepth 0
-mtime +1 -type f -name "*.flv" |xargs rm -f
The problem is that it doesn't delete the .flv files in a directory that are 1 or more days old.
How can I correct the above command?
EDIT: Paul - the command "ls -l /home/get/public_html/videos" results in 2000+ files but here is 2 of them that should be deleted:
-rw-r--r-- 1 get get 3501188 Jan 4 15:24 f486cf0a2b6bb40e4c50c991785084131231104229.flv
-rw-r--r-- 1 get get 10657314 Jan 4 17:51 f5f1490ddaa11a663686f9d06fb37d981231112941.flv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好在 find 中使用 -print0,在 xargs 中使用 -0,以防某个文件的名称不常见。
另外,您想使用 -maxdepth 1 在指定目录中实际查找某些内容。
-maxdepth 0 表示它只会在命令行列出的目录中查找,不会检查这些目录的内容。
It's better to use -print0 on find and -0 in xargs in case one file has an uncommon name.
Also, you want to use -maxdepth 1 to actually find something in the specified directory.
-maxdepth 0 means it'll only find in the directories listed in the command line, it won't check the contents of those directories.
您的意思是,如果您有一个目录
/home/get/public_html/videos/foo
它不会删除其中的文件? 这是因为您设置了-maxdepth 0
参数,这会阻止find
下降到子目录。Do you mean, if you have a directory
/home/get/public_html/videos/foo
it doesn't delete the files in them? That would be because you have the-maxdepth 0
argument set, which preventsfind
from descending into subdirectories.