Harsh Shandilya

Android developer, Kotlin fanatic and wannabe Rustacean

Tools of the trade: fd

Posted at — Aug 18, 2020

Continuing this series, let’s talk about fd.

What is fd?

fd is an extremely fast replacement for the GNU coreutils' find(1) tool. It’s written in Rust, and is built for humans, arguably unlike find(1).

Why do I use it?

Other than the obvious speed benefits, one of the most critical improvements you’ll notice in your workflow with fd is the presence of good defaults. By default fd ignores hidden files and folders, and respects .gitignore and similar files. Here’s a small comparison to show you the differences between fd and find(1)’s default behaviors.

Running both find and fd on the repository for this website, then piping the results into del.dog:

$ find | paste
$ fd | paste

If you check both those links, you’ll observe that find(1) has a significantly higher number of results compared to fd. Looking closely, you’ll also notice that find(1) has dumped the entire .git directory into the results as well, alongwith the public directory of Hugo which contains the built site. These are surely important directories, but you almost never want to search through your .git directory or build artifacts. fd shines here by excluding them automatically, while being significantly faster than find(1) even when they’re both returning the exact number of results.

On top of these, fd also comes with a very rich set of options that let you do many typically complex operations within fd itself.

Converting all JPEG files to PNG

$ fd -tf jpg$ -x convert {} {.}.png

Some new things here!

Finding and deleting all files with a specific extension

$ fd -HItf \\.xml$ -X rm -v

Mostly familiar now, but with some key differences.

Updating all git repositories in a directory

$ fd -Htd ^.git$ --maxdepth 1 -x hub -C {//} sync

Already feels like home!

hub is a git wrapper that provides some handy features on top like sync which updates all locally checked out branches from their upstream remotes. You can re-implement this with some leg work but I’ll leave that as an exercise for you.

And that’s about it! Let me know what you think of fd and if you’re switching to it, over on Twitter.

This was part 3 of the Tools of the trade series.