Day 36 - Grep: excluding files

12 May 2017

Grep argument of the day: --exclude and --exclude-dir.

It excludes some files or directories.

-I excludes binary files

$ git clone git@github.com:iadvize/devops-tip-of-the-day.git

$ grep -nr grep devops-tip-of-the-day/
../.git/hooks/commit-msg.sample:16:# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
../.git/hooks/commit-msg.sample:20:test "" = "$(grep '^Signed-off-by: ' "$1" |
../.git/hooks/pre-push.sample:44:		commit=`git rev-list -n 1 --grep '^WIP' "$range"`
../.git/hooks/prepare-commit-msg.sample:36:# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
Binary file ../.git/index matches
../_posts/2017-03-21-day-08-tree-command.markdown:61:Pretty usefull for grep parsing:
../_posts/2017-03-21-day-08-tree-command.markdown:64:$ tree -Cfi | grep .js$
...

$ grep -nr -I --exclude-dir={.bzr,CVS,.git,.hg,.svn} grep devops-tip-of-the-day/
../_posts/2017-03-21-day-08-tree-command.markdown:61:Pretty usefull for grep parsing:
../_posts/2017-03-21-day-08-tree-command.markdown:64:$ tree -Cfi | grep .js$
...
# ~/.bashrc
alias grep='grep -I --exclude-dir={.bzr,CVS,.git,.hg,.svn}'