Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling paths with whitespace that result from a backtick command

Tags:

bash

unix

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.

like image 931
Lanaru Avatar asked Dec 01 '25 14:12

Lanaru


1 Answers

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 '{}' \;
like image 136
anubhava Avatar answered Dec 04 '25 06:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!