Reputation: 431
find -mmin -19 -exec rm '{}'\;
It will find the modified files 1st and then remove them. but it gives me error as below, find: missing argument to `-exec'
Also tried various combinations like,
find -mmin -19 -exec rm '{}';\
find -mmin -19 -exec rm '{}'/;
Upvotes: 13
Views: 33174
Reputation: 1
Here is another option. Specify the date from which we want to delete the files:
find /SYSADMIT/* -type f -not -newermt "AAAA:MM:DD HH:MI:SS" -delete
Extracted from: https://www.sysadmit.com/2019/08/linux-borrar-ficheros-por-fecha.html
Upvotes: 0
Reputation: 368914
You need space between the command and \;
find -mmin -19 -exec rm {} \;
find
already provide -delete
option, so you don't need to use -exec rm ..
:
find -mmin -19 -delete
-delete
Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.
Warnings: Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified. When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and -delete together.
Upvotes: 30
Reputation: 12402
You're missing an essential space to separate the braces from the semicolon.
find -mmin -19 -exec rm '{}' \;
but this does the same ting, is easier to type, and probably executes faster.
find -mmin -19 -delete
Upvotes: 5