且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除文件使用shell脚本在Unix中早于10天

更新时间:2023-08-29 12:53:10

找到是这类任务的常用工具:

find is the common tool for this kind of task :

find ./my_dir/* -mtime +10 -type f -delete

说明


  • ./ MY_DIR 目录(用自己的替换)

  • -mtime +10 早于10天

  • 型的F 仅文件

  • -delete 毫不奇怪。删除前测试

  • ./my_dir your directory (replace with your own)
  • -mtime +10 older than 10 days
  • -type f only files
  • -delete no surprise. Remove it to test before

和照顾的 ./ MY_DIR 的存在是为了避免不良的惊喜!

And take care that ./my_dir exists to avoid bad surprises !