Get the highlights in your inbox every week.
Replace find with fd on Linux | Opensource.com
Replace find with fd on Linux
The fd command is a popular, user-friendly alternative to the find command.
Many Linux programmers use the
find command every single day of their career. But
find gives a limited set of filesystem entries, and if you have to do a large set of
find operations, it's not even very fast. So instead, I prefer to use the Rust
fd command because it provides sensible defaults that work for most use cases.
As its README says, "
fd is a program to find entries in your filesystem. It is a simple, fast, and user-friendly alternative to
find." It features parallelized directory traversal, so it can search multiple directories at once. It supports regular expressions (regex) and glob-based patterns.
On Linux, you can install
fd from your software repository (a list of available packages can be found on the fd page on Repology.) For example, on Fedora:
$ sudo dnf install fd-find
Alternately, you can use Rust's Cargo package manager:
$ cargo install fd-find
To do a simple search, run
fd after any argument, such as:
$ fd sh
If you want to search for a specific directory, provide the directory path as a second argument to
fd, such as:
$ fd passwd /etc
To search for a particular file extension, use
-e as an option. For example:
$ fd . '/home/ssur/exa' -e md
You can also execute a command by providing
-x/--execoption runs an external command for each search result (in parallel).
-X/--exec-batchoption launches the external command once with all search results as arguments.
For example, to recursively find all ZIP archives and unpack them:
$ fd -e zip -x unzip
Or, to list all files under a particular directory that were changed within the last n number of days, use the
$ fd . '/home/ssur/Work/' --changed-within 10d
And to search all files that were changed before a specific number of days, use the
--changed-before n option:
$ fd . '/home/ssur/Work/' --changed-before 365d
.acts as a wildcard entry to instruct
fdto return all files.
To learn about more the functionalities of
fd, consult its documentation on GitHub.
One thing I especially like about
fd is that the search pattern is case-insensitive by default, which makes it easier to find things even when you have imprecise knowledge about what you're looking for. Better yet, it automatically switches to case-sensitive if the pattern contains an uppercase character.
Another benefit is that it uses color-coding to highlight different file types.
If you are already using this amazing Rust tool, please let us know your thoughts in the comments.