how do I correctly negate zsh globbing expressions?
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".
Solution 1:
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:
- Match all file names ending with a dot
- if they aren't pipes
(^p)
, and - sort the matches
(o)
by "w
" => "unknown sort specifier"
See man zshexpn
=> FILENAME GENERATION
=> Glob Qualifiers
for more on this.