Finding stuff – find, grep, silver searcher, ripgrep

Here’s how to find stuff in a directory:

grep -r <keyword> .

or

find . -type f -exec grep <keyword> {} \; -print

or, to exclude a directory:

grep -r --exclude-dir=<directory> <keyword> .

 

And silver searcher is pretty neat. https://github.com/ggreer/the_silver_searcher

e.g. ag <keyword> .

Respects your .gitignore!

 

Having said that, it doesn’t recognise ** patterns in your .gitignore.

https://github.com/ggreer/the_silver_searcher/issues/530

If that’s an issue you might want to try ripgrep.

https://github.com/BurntSushi/ripgrep#installation

Incredibly, ripgrep posts timings that are 5x faster than Silver Searcher.

 

Leave a Reply

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