tags:

views:

327

answers:

3

I'm using the following command to remove every ".dummy" directories in a folder named "Test Folder":

rm -rf `find "Test Folder" -type d -name .dummy`

However, this doesn't work since it expands to, say:

rm -rf Test Folder/.dummy

Since the whitespace is not escaped, this fails.

I also tried something like this:

find "Test Folder" -type d -name .dummy -exec rm -rf {} \;

It works, but it gives an annoying error like this:

find: Test Folder/.dummy: No such file or directory

Is there a way to make either solution to succeed?

+2  A: 

Try

find "Test Folder" -type d -name .dummy -exec rm -rf \"{}\" \;

Note the extra quotes in the rm -rf "{}" arg to the -exec option. They're required because the name Test Folder/.dummy has a space in it. So you need quotes.

S.Lott
Are the extra quotes actually needed? I wasn't sure they were.
Beau Simensen
you want to \ escape the quotes at the {} -- otherwise they're eaten by the shell command line parse.
Charlie Martin
+6  A: 

A couple of things. Easiest is to change and use

$ find 'Test Folder' -type d -print0 | xargs -0 rm -rf

Another choice is

$ find 'Test Folder' -type d -exec \'{}\' \;
Charlie Martin
+1  A: 

find "Test Folder" -type d -name '.dummy' -delete