Search code examples
shellcommand-linesedterminalls

List all files that do not match pattern using ls


Possible Duplicate:
How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?

I've read the man page for ls, and I can't find the option to list all that do not match the file selector. Do you know how to perform this operation?

For example: lets say my directory is this:

> ls
a.txt b.mkv c.txt d.mp3 e.flv

Now I would like to do something that does the following

> ls -[SOME_OPTION] *.txt
b.mkv d.mp3 e.flv

Is there such an option?

If not, is there a way to pipe the output of ls to another function (possibly sed) that shows only the ones that I would like?

I don't know exactly how to do this, but I'm imagining it would be something like:

> ls | sed [SOMETHING] 

I really should learn how to use sed,awk,and grep, but I keep getting stuck at understanding how to write the regexes. I understand the concept of regular expressions clearly, but I get confused between regexes that use different syntax.

Any help would be much appreciated!

EDIT:

I forgot to mention that I am running Mac OS X, so the functions may be slightly different from the ones discussed in other answers for the unix/linux shell (hence some of my confusion with sed,awk,and grep).


Solution

  • this may be help you

    ls --ignore=*.txt
    

    It will not display the .txt files in your directory.