27

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".

2 Answers 2

41

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.

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

I was having this same issue trying to pull a branch down from git.

Example:feature/this_feature(error_1)

I had to escape the parenthesis: feature/this_feature\(error_1\)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .