美文网首页
linux中删除指定日期之前的文件

linux中删除指定日期之前的文件

作者: 寂风如雪 | 来源:发表于2019-12-20 12:37 被阅读0次

参考:
https://blog.csdn.net/weiyuefei/article/details/67633483(讲的更详细)
https://stackoverflow.com/questions/6495501/find-paths-must-precede-expression-how-do-i-specify-a-recursive-search-that

find /tmp -mtime +30 -type f -name '*.sh[ab]' -exec rm -f {} \;

/tmp --设置查找的目录;
-mtime +30 --设置时间为30天前;
-type f --设置查找的类型为文件;
-name '*.sh[ab]' --设置文件名称中包含sha或者shb,最好有引号,否则有时会报find: paths must precede expression
-exec rm -f --查找完毕后执行删除操作;
{} \; 一定要有否则报 find: missing argument to '-exec'
如果只查找当前目录而忽略子目录可以加 -maxdepth 1 最好加在 -mtime +30 之前,否则报find: warning: you have specified the -maxdepth option after a non-option argument -mtime, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

相关文章

网友评论

      本文标题:linux中删除指定日期之前的文件

      本文链接:https://www.haomeiwen.com/subject/cnobnctx.html