Two more (bash-specific) options for you. They both involving globbing
, and can be used with all commands.
1) Use extended globbing
shopt -s extglob
grep 'pattern' !(unwantedfile.txt|*.sh)
2) Add the names or patterns that you want to exclude (colon-separated) to the GLOBIGNORE shell variable.
Note that when GLOBIGNORE is set to a non-null value, it also automatically enables DOTGLOB as well, so hidden files will expand too. You need to include the ".*
" pattern if you want to exclude them as well. Also don't forget to unset GLOBIGNORE
, or otherwise change it, when you're finished.