Excluding symlinks while grepping

Please share if you found it helpful!

When grepping for a term, I usually face troubles with having to wade through results that are duplicated because symbolic links on my codebase. Excluding symlinks while grepping would save a lot of time. Let’s look at how to achieve that.

In order to exclude symlinks on search results of grep, I use a combination of find and grep like below:

The “-H” modifier on grep prints the path to the file along with the filename in the search result.

An useful thing to do would be to ignore the .git directories which can sometimes also spoil the search results. In order to do that, you could also pipe the output of the first find command to another grep that ignores the .git folders, but it’s a little slower than using the find command solely.

The below find command does it faster than piping it to grep when you want to avoid piping it to grep.

 

 

 

Like what you just read? Subscribe To Receive tips and tricks about:

Like what you just read? Subscribe To Receive tips and tricks about:

1. Linux

2. Web development

3. Developer life hacks

4. Web security

5. Entrepreneurship

Thanks for subscribing, hopefully I will make your life better by sharing all the tips and tricks that make my life easier.

Leave a Reply

Your email address will not be published. Required fields are marked *