On CentOS, how can I delete files which are created 5 mins ago or earlier in a folder? Thanks!
Asked
Active
Viewed 6,472 times
2 Answers
3
Try using find:
find ./ -mmin -5 -exec rm -i '{}' \;
-
`find ./ -mmin -5` returns nothing .. even there are some old files in the current folder – ohho May 23 '11 at 03:41
-
find ./ -mmin -5 should return a list of all files modified in less than or equal to five minutes. I tested this on my Debian system with success. Regardless, you want to use find to do this... – May 23 '11 at 07:00
-
`# find --version GNU find version 4.2.27 Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX ` on CentOS – ohho May 25 '11 at 08:52
-
1for files created 5 mins or earlier, it's `find . -cmin +5`. find . -cmin -5` is files created within last 5 minutes. `-cmin +5` is different from `-cmin 5`. thanks – ohho May 25 '11 at 08:56
3
Simmilar to kce:
find /path/to/folder -type f -cmin -5 -print0|xargs -r0 rm
Added a search for files only and used cmin instead of mmin as you asked for files created in the past five minutes. I like to combine find with xargs.
In UNIX, we typically refer to them as directories, not folders. I used your name in the path above.
-
I tried `find /tmp -type f -cmin -5` and it returns nothing (`find /tmp -type f` returns all files in `/tmp`. (CentOS) – ohho May 23 '11 at 06:22
-