Remove file isn't working

I'm trying to delete the files that are 5 days old..
Clearly the modified date is April 15 for workorders.sql
My code won't delete it. However if I use +4 then it will delete it. Am I missing something?

-rw-r--r-- 1 dbadmin dbadmin    1331824 Apr 15 18:34 wmweb_test.sql.gz
-rw-r--r-- 1 dbadmin dbadmin 6531478011 Apr 15 19:10 workorders.sql
find ~/delete/2020-04-15/*.sql -type f -atime +5 -exec rm -rf '{}' \;

I also tried with but it still doesn't delete the file.

find ~/delete/2020-04-15/*.sql -type f -mtime +5 -exec rm -rf '{}' \;
find ~/delete/2020-04-15/*.sql -type f -ctime +5 -exec rm -rf '{}' \;

Please specify your operating system details along with your shell.

mtime - modified time- time the file has been written / deleted from, displayed as Modify: ... using stat command against file.
ctime - creation time - time the file was created, displayed as Birth: .. using stat command against file (if maintained)
atime - access time - time the file was accessed, displayed as Access: .. using stat command against file (if maintained)

So trying those switches without understanding them, can delete a lot of stuff you probably do not want.

+4 is correct format, since +0 is 24 hours from the time find was executed.

user@host:~/files/sql$ date
Wed 22 Apr 2020 06:38:58 AM CEST
user@host:~/files/sql$ ls -lrt 
total 0
-rw-r--r-- 1 user user 0 Apr 17 16:00 workorders.sql
-rw-r--r-- 1 user user 0 Apr 22 06:18 wmweb_test.sql.gz

user@host:~/files/sql$ find /path/to/files/sql -type f -name "*.sql" -mtime +4 # nothing found, why ?

Lets look at the manual for -atime as it explains the rounding which happens on all time options :

Ok this makes is more clear, but how can i find what i want using GNU find ?

user@host:~/files/sql$ find /path/to/files/sql -daystart -type f -name "*.sql" -mtime +4
/path/to/files/sql/workorders.sql

If you are not using GNU find or need greater resolution from / to, that can be achived using touch with temporary files, and using -newer and ! -newer with find .
Forum is full of those examples, so use a search option please.

Hope that helps
Regards
Peasant.

3 Likes

Those results may depend on the time that you issue the find command. man find :

2 Likes

@peasant
Many thanks for your reply.

The OS is debian-linux-gnu

It looks like using atime is not the best choice and ctime is the ideal switch as the files in the folder won't be written once it is created.