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

Nifle
  • 34,203
  • 26
  • 108
  • 137
math
  • 2,633
  • 8
  • 31
  • 43

2 Answers2

40

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.

Sparhawk
  • 1,815
  • 15
  • 25
peth
  • 9,890
  • 3
  • 34
  • 41
  • 1
    ^*.owp did the job. whooa, for what *.(^owp) really does :) – math Mar 22 '12 at 14:19
  • 13
    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
  • 8
    @DBedrenko: thanks! N.B.: done via `setopt extendedglob` – Thomas M Jun 12 '17 at 07:16
  • 1
    I found [this](https://www.refining-linux.org/archives/37-ZSH-Gem-2-Extended-globbing-and-expansion.html) useful as a quick summary for anyone interested in glob qualifiers. – wardw Jan 19 '19 at 09: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\)

BlaineOmega
  • 253
  • 2
  • 4
  • 7