Quote:
Originally Posted by rmacd
-exec function of find executes rm on each file.
|
This is not quite true, how the -exec option behaves is determined by the ending character of the command. Usually you will use the ; ending character (which due to its function as a special character in the shell has to be escaped to \;), but you can also use the + ending character, which will behave similarly to xargs.
So you have several options to achieve the task, the most common would be:
1. If it is expected that the find command will find only a few files (which is the case for the OP) you can use
Code:
find /etc/test -type f -mtime +40 -exec rm '{}' \;
or
Code:
find /etc/test -type f -mtime +40 -delete
This will, as rmacd already stated, invoke the deletion on any found file separately, which will cause big overhead when many files are found.
2. If it is expected that a large number of files will be found it is better to use either
Code:
find /etc/test -type f -mtime +40 | xargs rm
or
Code:
find /etc/test -type f -mtime +40 -exec rm '{}' +
In both cases the found files will be assembled to sets of files and then the command is launched on a whole set of filenames(in the first case by the xargs command, in the second find will do the work). This will speed up the execution when large numbers of files are found.