Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to list files that don't match a glob?

E.g., let's say I have a directory that contains hundreds of files, 97% of which have the filename extension .png.

I know I can list the PNG files with:

ls *.png

But, how do I list the opposite, i.e., just the non-PNG files?

share|improve this question
up vote 6 down vote accepted

Using ls:

ls -I "*.png"

the quotes are important to stop the shell evaluating the *

Using find:

find . -not -name "*.png"

If you have subdirectories (with files), you may want to limit the search:

find . -maxdepth 1 -type f -not -name "*.png" 


  • -maxdepth 1 limits it to the present directory
  • -type f only allows it to print files
share|improve this answer
Hmm.. I get ls: illegal option -- I on Mac OS X 10.8. But using find works. So, thanks! :) – mattdipasquale Jul 11 '12 at 23:31
Interesting, I have no experience with Mac so I can't help there I'm afraid. If this answered your question, though, please can you accept it by pressing the hollow tick next to the answer. Thanks :-) – Jay Jul 11 '12 at 23:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.