在 Unix 中使用 shell 脚本删除超过 10 天的文件 [英] Delete files older than 10 days using shell script in Unix
本文介绍了在 Unix 中使用 shell 脚本删除超过 10 天的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 shell 脚本的新手,有人可以帮忙吗?我想将文件夹中的脚本从当前日期删除回 10 天.脚本如下所示:
I'm new to shell scripts, can anyone help? I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like:
2012.11.21.09_33_52.script
2012.11.21.09_33_56.script
2012.11.21.09_33_59.script
脚本将使用 Crontab 每 10 天运行一次,这就是我需要当前日期的原因.
The script will run in every 10 day with Crontab, that's why I need the current date.
推荐答案
find
是此类任务的常用工具:
find
is the common tool for this kind of task :
find ./my_dir -mtime +10 -type f -delete
说明
./my_dir
您的目录(替换为您自己的)-mtime +10
超过 10 天-type f
仅文件-delete
并不奇怪.在执行整个命令之前删除它以测试您的find
过滤器
./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 yourfind
filter before executing the whole command
并注意 ./my_dir
的存在以避免意外!
And take care that ./my_dir
exists to avoid bad surprises !
这篇关于在 Unix 中使用 shell 脚本删除超过 10 天的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文