Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to delete all files with a given name in all the subdirectories of my home directory.

I tried:

rm -r file

in my home directory, but it didn't work because that file doesn't exist in that directory.

share|improve this question
up vote 10 down vote accepted

find . -name "filename" -delete

share|improve this answer

as an elaboration on @tante's answer, you may wish to ensure the file list used is correct before deleting those files:

find <source_dir> -name <filename> -print

if inspection shows valid list then

find <source_dir> -name <filename> -delete

another option if wanting this over many directories using a temporary holding directory:

mkdir <dest_dir>
for i in <list_of_directories>
  find "$i" -name <filename> -exec /bin/mv {} <dest_dir>

# check dest_dir
ls dest_dir
rm -rf <dest_dir>

As always, please ensure the accuracy of any scripts before execution and always have a backup ready in-case something goes wrong.

share|improve this answer
Thanks for that! – oadams Nov 1 '10 at 9:48
always put double quotes around variable substitutions, or your command won't work with file names containing certain special characters (whitespace, wildcards and backslashes). – Gilles Nov 1 '10 at 18:15
@Gilles - Yes, thanks for updating and ensuring this answer was correct. – Wayne Nov 3 '10 at 23:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.