Here\'s how one might list all files matching a pattern in bash:
ls *.jar
How to list the complement of a pattern? i.e. all files not match
Another approach can be using ls -I
flag (Ignore-pattern).
ls -I '*.jar'
If your ls
supports it (man ls
) use the --hide=<PATTERN>
option. In your case:
$> ls --hide=*.jar
No need to parse the output of ls
(because it's very bad) and it scales to not showing multiple types of files. At some point I needed to see what non-source, non-object, non-libtool generated files were in a (cluttered) directory:
$> ls src --hide=*.{lo,c,h,o}
Worked like a charm.
And if you want to exclude more than one file extension, separate them with a pipe |
, like ls test/!(*.jar|*.bar)
. Let's try it:
$ mkdir test
$ touch test/1.jar test/1.bar test/1.foo
$ ls test/!(*.jar|*.bar)
test/1.foo
Looking at the other answers you might need to shopt -s extglob
first.
One solution would be ls -1|grep -v '\.jar$'
ls | grep -v '\.jar$'
for instance.
Little known bash expansion rule:
ls !(*.jar)