This question already has an answer here:

I have a directory containing several files:

$ ls tdir
xx  yy zz

I'm looking for a zsh glob pattern, which expands to all (non-dot)-files except xx. This is what I tried:

$ echo tdir/*~xx
tdir/xx tdir/yy tdir/zz

As we can see, this does not work; *~xx is not expanded in the way I expected. How do I write this correctly?

marked as duplicate by don_crissti, chaos, Gilles zsh Feb 11 '16 at 0:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Feb 10 '16 at 21:13

This question came from our site for professional and enthusiast programmers.


The glob~filter (and-not) operator applies a filter as a negative pattern matching on the result of the whole glob.

That allows things like:

grep foo ./**/*~*/.svn/*(.mh-1)

for instance.

Here, you'd need:

echo tdir/*~tdir/xx


echo tdir/*~*/xx


echo tdir/(*~xx)

Or use the ^ negation operator instead:

echo tdir/^xx

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