I would like to delete files that are older than 59 minutes. I have this so far:
find /tmp -daystart -maxdepth 1 -mmin +59 -type f -name "*.*" -exec rm -f {} \;
This doesn't work and seems to delete all files. I've tested this several times and I think the issue is to do with daystart
.
I've read the man page and it seems to base time on the beginning of the day rather than from 24 hours ago. If this is the case how can I accurately delete files that are older than 59 minutes? Do I need to account for daystart
and add some more minutes?
Example:
ubuntu@ip-10-138-30-118:/tmp$ ls -la total 8 drwxrwxrwt 2 root root 4096 Jul 20 14:39 ./ drwxr-xr-x 23 root root 4096 Jun 25 18:34 ../ -rw-rw-r-- 1 ubuntu ubuntu 0 Jul 20 12:35 a.txt
Both the following commands, return the file:
ubuntu@ip-10-138-30-118:/tmp$ find /tmp -daystart -maxdepth 1 -mmin +59 -type f -name "*.*" /tmp/a.txt
And:
ubuntu@ip-10-138-30-118:/tmp$ find /tmp -daystart -maxdepth 1 -mmin +359 -type f -name "*.*" /tmp/a.txt
However, the file is not older than 659 minutes (10.9 hours)! But at 759 (12.65 hours), it doesn't return the file anymore?
-mtime +7 : only consider the ones with modification time older than 7 days. -execdir ... \; : for each such result found, do the following command in ... . rm -- '{}' : remove the file; the {} part is where the find result gets substituted into from the previous part.
When used with -mmin
, -daystart
appears to make it calculate from the end of today, not the beginning.
If you just want to find files modified more than 59 minutes ago, you don't need that option. -mmin
calculates from the current time by default.
barmar@dev:~/testdir$ date Sat Jul 20 10:02:20 CDT 2013 barmar@dev:~/testdir$ ls -l total 0 -rw-r--r-- 1 barmar adm 0 Jul 20 09:57 a.txt barmar@dev:~/testdir$ find . -maxdepth 1 -mmin +2 -type f ./a.txt barmar@dev:~/testdir$ find . -maxdepth 1 -mmin +10 -type f
this should work for you
find /path -mmin +59 -type f -exec rm -fv {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With