Recursively delete certain files
Using the find command, you can locate and delete files based on many attributes such as filetype. This recipe will demonstrate how to find and delete files based on part of their filename.
To find and delete all files on the system that end in .log, run this as superuser:
find / -name \*.log -exec rm {} \;
The backslashes (\) are important in this command. Using the -exec option allows an arbitrary command, in this case rm, to be used with the filename substituted in place of the {} characters.
This would be a dangerous command to execute, so a safer alternative uses the -ok command instead of the -exec. When used this way, find will prompt you before each execution of the command following -ok. To optionally delete all files ending with .tmp in the /var filesystem, use:
find /var -name \*.tmp -ok rm {} \;






Add New Comment
Viewing 3 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment