Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 wrote the following snippet to delete several subdirectories selectively from a common ancestor. It doesn't work, but I can't tell why.

for x in *; 
do rm -r "$x/foo/bar/{a*,b,c,d,g*}"; 

I get "no such file or directory" errors when I run it, even though I know that the folders exist.

share|improve this question
In zsh, you don't need the quotes at all. You do need the quotes in other shells. Except that here, you can write rm -r */foo/bar/{a*,b,c,d,g*} (in zsh, make that rm -r */foo/bar/{a*,b,c,d,g*}(N), where the N glob modifier indicates that you want to skip non-matching patterns rather than signal an error). – Gilles Nov 18 '11 at 10:33
up vote 4 down vote accepted

Brackets won't expand inside double quotes. Try this:

for x in *; 
do rm -r "$x/foo/bar/"{a*,b,c,d,g*}; 
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.