Tag Archives: grep ignore symbolic links

Excluding symlinks while grepping

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.