Eureka!
Charly's Column – find and fd
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
find /test/* -mtime +365 -exec rm {} \;
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.
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 …
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4