In bash
, if the extendedglob
option is set (it is by default), you can negate a glob pattern by wrapping it in parentheses and prepending a bang (!
). For example, !(*.gz)
matches all items whose names don't end with .gz
. See the Pathname Expansion
subsection in the EXPANSION
section in the bash
manual page for more information.
In zsh
, if the extglob
option is set (it is not, by default), you can negate a glob pattern by prepending a caret (^
). For example, ^*.gz
matches all items whose names don't end with .gz
. See the FILENAME GENERATION
section in the zshexpn
manual page for more information.
Note that in general, if you want to use ls
with a glob pattern, you should specify -d
. This is because the shell expands the glob pattern into a list of matching names, passing each one to ls
as a separate argument. If you don't use -d
, ls
will list the contents of any directories whose names it's given.