"Finding Files at the Command Prompt"

linux command line

Here's a quick look at a few handy command-line tools for finding files based on their contents:


fd is an improvement on the standard Linux find tool. It's both faster, and the options are more intuitive.

Here's a working example to show Subject and Date for all emails updated within 10 days. The following may be run from the root of a MailDir folder:

# Find all files updated in the last 20 days and extract a Subject and Date
fd --changed-within 20d --type f --exec grep -P "^(Subject|Date)" \; .

Important Note: \; is used to identify the end of the --exec command, and allows you to specify a path afterwards.

By default .gitignore files are honoured, which is especially helpful when searching through a repository.

Link: https://github.com/sharkdp/fd

ag - The Silver Searcher

The Silver Searcher or ag is a really fast tool for scanning the contents of files. It's apparently written as a faster replacement for ack, and works in a similar way to grep.

By default, it will search for a pattern in all subfolders while ignoring files listed in .gitignore, and can be configured to globally ignore specific files of your choice.

Link: https://github.com/ggreer/the_silver_searcher

rg - RipGrep

This appears to be a more recent, similar app to ag and is purportedly faster. It's an easy drop-in replacement and I've already started using it.

Link: https://github.com/BurntSushi/ripgrep

Published on 2019-05-30