First of all, -mtime 15
brings the files modified exactly 15 days ago. If you want the ones that were modified there is plus 15 days, use -mtime +15
.
As for the option -exec
, lacked to put a \;
:
find -name '*.log*' -mtime 15 -exec rm -f {} \;
Or a +
:
find -name '*.log*' -mtime 15 -exec rm -f {} +
The difference is that the first option executes the command rm -f
once for each file found, while the second option passes several file names at once to the rm -f
, reducing the number of times the control rotates.
Another option is to make one pipe (|
) and use the command xargs
:
find -name '*.log*' -mtime 15 |xargs rm -f
With that, the exit of find
(filenames) are passed as parameters to the command rm -f
(similar to the option with +
above).
View documentation for more details.
Thank you very much, it worked
– Lucas Marinzeck