How to delete files using find and rm?

find -mmin -19 -exec rm '{}'\; 

It will find the modified 1st files and then delete them. but this gives me an error, as shown below, find: the `-exec 'argument is missing

Also tried to use various combinations, such as

 find -mmin -19 -exec rm '{}';\ find -mmin -19 -exec rm '{}'/; 
+6
source share
2 answers

You will need a space between the command and \;

 find -mmin -19 -exec rm {} \; 

find already provides the -delete option, so you don't need to use -exec rm .. :

 find -mmin -19 -delete 

-removed

Delete files true if the deletion succeeded. If the deletion failed, an error message is displayed. If -delete does not work, find the exit status to be non-zero (when it eventually exits). Automatic use of -delete enables the -depth option.

Warnings. Do not forget that the search command line is evaluated as an expression, so setting -delete first will cause find to try to delete everything below the starting points that you specified. When testing, find the command line that you are going to use later with -delete, you must explicitly specify -depth to avoid later surprises. Since -delete implies -depth, you cannot use -prune and -delete together with benefit.

+8
source

You do not have enough space to separate the curly braces of the semicolon.

 find -mmin -19 -exec rm '{}' \; 

but it does the same, is easier to type in, and probably runs faster.

 find -mmin -19 -delete 
+4
source

All Articles