18

I want to list all files but those ending with owp: Hence I tried:

  ls -l *.(^owp)
  zsh: unknown sort specifier
  ls -l *(^owp) 
  zsh: unknown sort specifier
  ls -l *[^o][^w][^p] # does not work either, missing some files

none worked. How do I that in a correct manner? My .zshrc has "set extendedglob".

27

Try either:

ls -l ^*.owp

(i.e. match anything except the pattern *.owp)

or:

ls -l *~*.owp

(i.e. match anything that matches the pattern * but does not match *.owp)

See man zshexpn => FILENAME GENERATION => Glob Operators for more on this.


Appended () in glob patterns are for glob qualifiers, whereas you want a glob operator.

What *.(^owp) does is:

  1. Match all file names ending with a dot
  2. if they aren't pipes (^p), and
  3. sort the matches (o) by "w" => "unknown sort specifier"

See man zshexpn => FILENAME GENERATION => Glob Qualifiers for more on this.

  • 1
    ^*.owp did the job. whooa, for what *.(^owp) really does :) – math Mar 22 '12 at 14:19
  • 9
    For anyone who can't get this to work, you need to set the extendedglob option in Zsh. – DBedrenko May 31 '14 at 13:54
  • 7
    @DBedrenko: thanks! N.B.: done via setopt extendedglob – Thomas M Jun 12 '17 at 7:16
  • 1
    I found this useful as a quick summary for anyone interested in glob qualifiers. – wardw Jan 19 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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