How to invert a grep expression

sMaN picture sMaN · Dec 7, 2010 · Viewed 232k times · Source

The following grep expression successfully lists all the .exe and .html files in the current directory and sub directories.

ls -R |grep -E .*[\.exe]$\|.*[\.html]$  

How do I invert this result to list those that aren't a .html or .exe instead. (That is, !=.)

Answer

Eric Fortis picture Eric Fortis · Dec 7, 2010

Use command-line option -v or --invert-match,

ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$