Delete Files Older Than x Days on Linux
来源:互联网 发布:天猫淘宝店费用预算 编辑:程序博客网 时间:2024/05/17 03:45
The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.
Command Syntax
find /path/to/files* -mtime +5 -exec rm {} \;
Note that there are spaces between rm, {}, and \;
Explanation
- The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
- The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
- The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.
This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.
0 0
- Delete Files Older Than x Days on Linux
- Linux Bash script to remove files older than 3 days
- Batch script to delete file older than N days
- Delete log files longer than 45 days
- error: newly created file is older than distributed files!
- configure: error: newly created file is older than distributed files!
- freebsd安装发生错误:newly created file is older than distributed files!
- configure: error: newly created file is older than distributed files! 错误处理
- 编译错误:configure: error: newly created file is older than distributed files!
- read and X permission on files in Linux
- Godaddy OA:delete node larger than X
- delete all the cvs files on XP
- Viewing text files on Linux
- delete files
- How to Manually Update Bash to Patch Shellshock Bug on Older Fedora-Based Linux Systems
- Linux Log files and usage on Ubuntu
- How to recover deleted files on Linux
- error: newly created file is older than distributed
- BeanUtils.populate的作用
- Java内存结构
- HDAC
- Spring系列之IOC
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- Delete Files Older Than x Days on Linux
- 【9001】Internet消息发布
- 文件的访问权限控制
- 数据库时间段查询
- 从苏宁电器到卡巴斯基第16篇:我在苏宁电器当营业员 VIII
- python学习——POP3收取邮件
- 第几天?
- 【HD 1865】 1string ( 大数与斐波那契数列 )
- hdu 5720 wool