Removing directories with spaces with bash

I am using the following command to delete all ".dummy" directories in the "Test Folder":

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

      

However, this does not work, as it expands to, say:

rm -rf Test Folder/.dummy

      

Since the space is not escaped, this fails.

I have also tried something like this:

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

      

It works, but it throws an annoying error:

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

      

Is there a way to make any solution successful?

+1


source to share


3 answers


A few things. The easiest way is to change and use

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

      



Another choice is

$ find 'Test Folder' -type d -exec \'{}\' \;

      

+9


source


Try

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

      



Note the extra quotes in the argument rm -rf "{}"

for the parameter -exec

. They are required because the name Test Folder/.dummy

has a space in it. Therefore, you need quotes.

+2


source


find "test folder" -type d -name '.dummy' -delete

+1


source







All Articles