Lanaru
Lanaru

Reputation: 9721

Handling paths with whitespace that result from a backtick command

Trying to remove certain folders from my directory tree.

rm -r `find -name .sbas`

For some folders it fails like this:

rm: cannot remove ‘./Reports/Report’: No such file or directory
rm: cannot remove ‘11/.sbas’: No such file or directory

The whitespace in the folder path is confusing the command into thinking it's getting two different paths.

What's the best way to handle this? Removing the whitespace from the folder names is not an option.

Upvotes: 3

Views: 240

Answers (1)

anubhava
anubhava

Reputation: 785581

Don't use output of find in rm like that.

Use find -delete:

find . -name .sbas -delete

Or on systems where find doesn't support delete use:

find . -name .sbas -exec rm -r '{}' \;

Upvotes: 3

Related Questions