How to invert a grep expression
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, !=
.)
Solution 1:
Use command-line option -v
or --invert-match
,
ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
Solution 2:
grep -v
or
grep --invert-match
You can also do the same thing using find
:
find . -type f \( -iname "*" ! -iname ".exe" ! -iname ".html"\)
More info here.