Find and Delete Files Recursively from Linux Command Line

Posted by jason on June 23, 2011, 10:53 a.m.
Tags: linux sysadmin

Here's a basic example of how to find files and delete them, recursively.

find  -name  -exec rm -rf {} \;

That command will look under the directory for all files matching and delete them. Not that you need to escape special characters in the with a backslash.

Play it safe

You probably shouldn't be deleting things recursively with "rm -rf" unless you know what you're doing. Run this command to see what files will match before deleting:

find  -name  -exec ls -l {} \;


Suppose you want to delete all files named *.nfo from the current directory. First, double-check you have things right:

find . -name \*.nfo -exec ls -l {} \;

If you want all the files listed to be deleted, then:

find . -name \*.nfo -exec rm -rf {} \;