Reputation: 3937
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, !=
.)
Upvotes: 337
Views: 387374
Reputation: 13120
As stated multiple times, inversion is achieved by the -v
option to grep
. Let me add the (hopefully amusing) note that you could have figured this out yourself by grepping through the grep
help text:
grep --help | grep invert
-v, --invert-match select non-matching lines
Upvotes: 31
Reputation: 17370
Use command-line option -v
or --invert-match
,
ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
Upvotes: 469
Reputation: 21155
Add the -v
option to your grep
command to invert the results.
Upvotes: 37