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.

 

 

 

Enjoyed reading this piece? Subscribe to my newsletter

Enjoyed reading this piece? Subscribe to my newsletter

Exclusive insights from an engineer turned product manager on his journey to entrepreneurship. Packed with insights and learnings from my personal journey. Learn something new every week.

Thanks for subscribing!

Leave a Reply

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