Many Linux programmers use the find command every day of their careers. But find has a limited number of file system entries, and if you do a lot of find operations, it’s not even very fast. Therefore, I prefer to use the Rustfd command instead, because it provides reasonable defaults for most usage situations.

As its README says, “FD is a program that looks for items in your file system. It is a simple, fast, and user-friendly alternative to find. It features parallel directory traversal, so it can search multiple directories at once. It supports regular expressions (Regex) and Glob based patterns.

Install the fd

On Linux, you can install FD from your software library (a list of available packages can be found on the FD page on Repology.) For example, on Fedora.

$ sudo dnf install fd-find

On macOS, use MacPorts or Homebrew.

Alternatively, you can use Rust’s Cargo package manager.

$ cargo install fd-find

The use of fd

To do a simple search, run fd after any argument, for example.

$fd sh ecc6299db9ec823 / cc registry/src/github.com - 1-1.0.67 / SRC/bin/GCC - shim. Rs Ecc6299db9ec823 / exa - registry/src/github.com - 1 0.10.1 completions/completions. The bash Ecc6299db9ec823 / exa - registry/src/github.com - 1 0.10.1 completions/completions. The fish Ecc6299db9ec823 / exa - registry/src/github.com - 1 0.10.1 completions/completions. The ZSH Ecc6299db9ec823 / exa - registry/src/github.com - 1 0.10.1 xtests/run. Sh Ecc6299db9ec823 / git2 registry/src/github.com - 1-0.13.18 / SRC/stash. Rs Registry/src/github.com - 1 ecc6299db9ec823 / libc - 0.2.94 / SRC/Unix/solarish Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / cmake/SelectHashes cmake Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / include/git2 / stash. H Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / include/git2 / sys/hashsig. H Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / script/backport. Sh Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / script/leaks. Sh Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2 / script/valgrind. Sh Ecc6299db9ec823 / libgit2 registry/src/github.com - 1 - sys - 0.12.19 + 1.1.0 / libgit2. / SRC/config_snapshot c [...].Copy the code

If you want to search for a specific directory, provide the directory path as the second argument to fd, for example.

$ fd passwd /etc
/etc/pam.d/passwd
/etc/passwd
/etc/passwd-
/etc/security/opasswd
Copy the code

To search for a specific file extension, use the -e option. For example.

$ fd . '/home/ssur/exa' -e md
/home/ssur/exa/README.md
/home/ssur/exa/devtools/README.md
/home/ssur/exa/man/exa.1.md
/home/ssur/exa/man/exa_colors.5.md
/home/ssur/exa/xtests/README.md
$ 
Copy the code

You can also execute a command by supplying -x or -x.

  • -x/--execOption to run an external command (in parallel) for each search result.
  • -X/--exec-batchOption to launch an external command as an argument for all search results.

For example, find all the ZIP files recursively and unzip them.

$ fd -e zip -x unzip

Or, to list all files in a particular directory that have changed in the past _n_ days, use the –changed-within option.

$ fd . '/home/ssur/Work/' --changed-within 10d
/home/ssur/Work/wildfly/connector/src/main/java/org/jboss/as/connector/subsystems/data_sources/JdbcDriverAdd.java
/home/ssur/Work/wildfly/connector/src/main/java/org/jboss/as/connector/subsystems/data_sources/JdbcExample.java
[...]
Copy the code

Instead, to search for all files that changed before a certain number of days, use the — change-before _n_ option.

$ fd . '/home/ssur/Work/' --changed-before 365d

Here,. Is a wildcard entry, instructing fd to return all files.

To learn more about fd’s capabilities, check out the documentation on GitHub.

conclusion

I particularly like FD because its search mode is case-insensitive by default, which makes it easier to find things even if you have an imprecise understanding of what you’re looking for. Even better, if the schema contains an uppercase letter, it is automatically converted to case sensitive.

Another benefit is that it uses color coding to highlight different file types.

If you’re already using this amazing Rust tool, let us know what you think in the comments.