Find by -name and -mtime, returns nothing

1.1k Views Asked by At

I am trying to use find command to delete some old file from backup folder but the find command return nothing, and so nothing is being removed! this is the code (find part), my system is ubuntu 18.04 LTS

find  -name "*.sql" -type f -mtime +30 

the result of find command

and the output of ls -l command is : the result of ls -l command

I googled and searched the web but did find nothing to solve the problem. any help appreciated.

1

There are 1 best solutions below

3
VeRo On

You are missing the starting point for your find command, in this case . because you already execute the command in the target directory:

find . -name "*.sql" -type f -mtime +30 

the rest can stay the same. First make sure it gives you the correct result and afterwards you can tack on the -exec to execute a command for each line of the result.

find . -name "*.sql" -type f -mtime +30 -exec rm '{}' ';'

You can usually find such answers on the UNIX stackexchange: How to execute ln on find results

Please see the comment from David in this particular case it might be a misunderstanding of the mtime parameter.

I have tested exactly the commands that were listed here, below you see my preparation and some multiple usage, you can see how the files show up as expected, every time the mtime value decreases:
VIRTUAL BOX UBUNTU LTS 18.04

which is no surprise, given the man page of the find command:
FIND MAN PAGE / -mtime PARAMETER

please check for any typos... this should work.