I have seen on some Linux, that
grep is configured to highlight the match, and print the matching file.
How can I configure
grep to highlight matches?
Also one of my favorites:
will list all pids of processes that match the name of some-hanging-process which you can use in following situation:
I've found that the best way to pimp grep is to use ack, which is essentially recursive grep with an intelligent ignore list (e.g., doesn't search .svn directories, ignores backup files, etc.), colour highlighting of results and perl regexps. It's what you want grep to do 98.6% of the time.
I set this in my .bashrc , instead of redefining grep using an alias:
For me, this works on Linux, MacOSX & FreeBSD.
I'd recommend avoiding the environment variable GREP_OPTIONS, it will affect every invocation of grep, even those embedded within other tools. If those tools expect grep to behave one way, and you change that behaviour, it will and does break those tools.
Instead, you can create an alias, which works well. This will only affect calls to grep from your interactive shell (i.e. that you type yourself).
The final option, that I like most of all, is to create a wrapper script that invokes grep. I prefer this over an alias, because I can invoke this wrapper from other programs. E.g. in vim by setting vimgrep, so that my searches from within vim behave identically to searches at the command-line.
Invoke this using:
will search for instances of 'pattern' in all text files in the current dir and subdirs.
Notice that I call my script 'grp', rather than shadowing 'grep', so that I'm always aware of whether I'm invoking grep with my customised defaults or not.
By default I include:
I think everyone would want to skip source control dirs: .hg .git .bzr .svn
Skipping 'build' and 'dist' are Python-isms, and probably don't apply to most people. No doubt you'll develop your own idiosyncrasies as you work.
'tags' is the output of ctags, that I use for 'go to function definition' and the like in tools like vim. As such it contains at least one copy of every word and symbol from my source code, so it's worth skipping from your search results.
"$*" at the end is the bash syntax for "and all the other params from the command-line", so you can pass in the pattern and dir to search as normal, and override any other command line flags you'd like.
The color should be encoded using ANSI color codes, for reference
Since I didn't see any examples of actually setting colors, here is a simple setup for GNU grep:
Be careful about