Charly's Column – find and fd

Article from Issue 241/2020

Fd is an uncomplicated find replacement that discovers lost treasures in the filesystem in next to no time. Charly would love to deploy an amazing tool like this in the analog world of his office.

I'm not very good at sorting things sensibly and then finding them again – both in my office and on my computers' filesystems. For the latter, at least I have electronic help in the form of tools like find and, more recently, fd.

The find command existed on Unix systems long before Linux was invented – in fact, it's older than most of the people who use it. On many of my systems, there is a directory named /test where I try things out. Anything that proves useful is sent to Git; the rest just hangs around gathering dust until the cron job in Listing 1 sweeps it away without write access after 365 days.

Listing 1

Crontab Entry


While doffing a hat to the now impressive power of the GNU implementation of find [1], you still sometimes find yourself wishing for a tool that can perhaps do a little less, but one that is more intuitive to use. This is where fd [2] jumps into the breach. The compact younger sibling of find, fd has already made its way into many distributions, but often only recently. In Ubuntu, it is available starting with version 19.04, for example.

After installing fd on my test Ubuntu, I now have an fdfind command. But the developers make it quite clear that their tool is named fd and use this name in all the examples. In order to permanently teach my system the short form, I just added an alias fd=find entry to my .bashrc.

Quickly perusing the man page reveals that fd can definitely do less than find, but it does what it does well, intuitively, and quickly. Typing fd without any further parameters returns the current directory's contents including all its subfolders, but without the hidden files and directories – like ls, but recursively. If the environment variable LS_COLOR is set (which is the default on most systems), the output will be in color.

Things become more interesting if you are searching for a file name or name component. In Figure 1, I told fd to search the root directory \ for rng. As you can see, it also found PatternGrammar.txt (at the very bottom). This is because fd is not case-sensitive by default. However, if an uppercase letter is stipulated as the search term, it switches its behavior and only returns case-specific results.

Figure 1: Without concrete instructions, fd ignores the case, but it can even handle regular expressions if necessary.

You can search for file extensions with the -e parameter. For example, to find all PNG images in and below the current directory, just type:

fd -e png

I use regular expressions for fine tuning. By way of an example, the command

fd '^a.*png$'

finds file names that start with a and end with png. The GitHub page [2] for the tool explains many more applications and parameters.

Now all I really need is a physical fd counterpart to tidy up my office …

The Author

Charly Kühnast manages Unix systems in a data center in the Lower Rhine region of Germany. His responsibilities include ensuring the security and availability of firewalls and the DMZ.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • The sys admin's daily grind: Smorgasbord

    Sys admin columnist Charly Kühnast has an electronic note box in which he collects ideas and small snippets of code. He calls it his "quarry" and is taking this opportunity to offer up some collectors' items to regular readers.

  • Charly's Column: Corkscrew

    Sys admin columnist Charly never takes a vacation from the Internet. A beach bar with WiFi is quickly found, but it runs a forced proxy, which thinks that the SSH port (22) is in league with the devil and blocks the connection. Time to drill a tunnel.

  • Charly's Column

    Debian fans appreciate the ability to update their systems to a new release without having to reinstall. The Deborphan tool takes care of the victims of the upgrade by searching for orphaned packages on which no other packages depend.

  • The sys admin's daily grind: urlwatch

    Experienced system administrators attach great importance to always being up to date when it comes to information technology. Urlwatch is a command-line tool that presents the latest news from websites that do not offer RSS feeds by email.

  • The sys admin’s daily grind: Sysdig

    In this issue, sys admin columnist and tool veterinarian Charly Kühnast invites Sysdig, the jack-of-all-trades among system diagnostic tools, into his surgery for a quick checkup. The project promises to unite the functionality of lsof, iftop, netstat, tcpdump, and others.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95