I need to remove jpg files from within a directory tree, but I only need to remove files that are less than n days old. Eg Delete jpg images that are 3 days or less from being created.
This is what I have so far but it doesn't work:
$ find ~/la/ruta -name *.jpg -mtime -2 -exec rm {} \;
zsh: no matches found: *.jpg
$ find la/ruta/*.jpg -mtime -2 -exec rm {} \;
zsh: no matches found: la/ruta/*.jpg
I have done the installation of
zsh
, and when trying to reproduce your problem, indeed, it throws the same error.Generally, when using the parameter
-name
or-iname
in the commandfind
, quotes are used, be they single or double. Leaving the command like this:You can also use
-iname
, in case any of the files have the extension.JPG
. Since it-iname
ignores if they are uppercase or lowercase.Regarding the creation date , we could look at an example:
1) We create a file.
2) Let's look at the date.
We get this result:
3) We add some information to the file.
4) Let's look at the date again.
We get this result:
The creation date is not a data that can be accessed according to the POSIX standard , since it defines 3 dates for a file, according to this documentation .
And in this Stack Exchange question , I quote:
Whose main idea in Spanish, means:
What gives us to understand that if the file is modified, it will be very difficult to search for it and delete it by date of creation.
Conclusion
To delete the files with less than N days , it would suffice to do the following:
Just replace the N with the number of days.
But if what you want is just to delete directories: