File Listing – How to List Every File Except Those with Specified Extensions

findgrepls

Suppose that I have a folder containing .txt, .pdf, and other files. I would like to list the "other" files (i.e., files not having the extensions .txt or .pdf). Do you have any advice on how to do this?

I know how to list files not having a given extension. For example, if I want to list all files except the .txt files, then either

find -not -iname "*.txt"

or

ls | grep -v '\.txt$' | column

seem to work. But, how can I list everything except .txt files or .pdf files? It seems that I need to use some sort of logical "or" in find or grep.

Best Answer

Assuming one has GNU ls, this is possibly the simplest way:

ls -I "*.txt" -I "*.pdf"

If you want to iterate across all the subdirectories:

ls -I "*.txt" -I "*.pdf" -R
Related Question