Super User is a question and answer site for computer enthusiasts and power users. 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 have a directory db-cache-db and there are a bunch of them under /home/{USER}/public_html. I know there is a way to write a script to that but I am not sure where or how to start.

I tried the following but no luck

find /home -wholename 'db-cache-db' -exec echo "rm -rf" {} ';'

Do I need to use -type and -name?

share|improve this question

migrated from May 1 '13 at 18:11

This question came from our site for professional and enthusiast programmers.

So what did it do? Did it echo what you asked it to? – Useless May 1 '13 at 14:40
Be careful people executing this command, it can be dangerous if not properly deployed! – fedorqui May 1 '13 at 14:45
It didn;t find the direcotires to remove them – cierra.specs May 1 '13 at 14:51
find -delete should work. – ignis May 1 '13 at 19:41

-wholename is the same as -path, and matches the full path of the directory, e.g. /home/{USER}/public_html/db-cache-db, not just the name, e.g. db-cache-db. Since you don't use a wildcard argument (e.g. */db-cache-db), you'll never find anything.

Try the following first, to make sure you'll not accidentally delete more than you intended:

find /home -name 'db-cache-db' -type d

If this results in the directories you want to delete, add the last argument that actually deleted:

find /home -name 'db-cache-db' -type d -exec rm -rfv {} \;
share|improve this answer

This is not a safe thing to do:

find /home -name 'db-cache-db' -type d -exec echo rm -rf {} ';'

You could lose lots of directories you want to keep.

find /home -name 'db-cache-db' -exec echo "rm -rf" {} ';' > /home/tmp.shl

Next read what is in tmp.shl, be sure everything is safe. Execute the script you "wrote" with find.

chmod +x /home/tmp.shl 
share|improve this answer
-exec echo is very safe, it just prints. – Daniel Beck May 1 '13 at 18:16
The original did not have echo. FWIW. – jim mcnamara May 1 '13 at 21:02
Rather than use -exec echo rm ... where you could accidently forget to type echo, isn't it the same effect to test using -print. – Kevin Fegan May 1 '13 at 22:18
@KevinFegan I've used echo rm or similar before, to show me the commands that will get executed. If I only wanted the file names though, -print would be sufficient. – Daniel Beck May 2 '13 at 6:24

Your Answer


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