A friendly alternative to the find tool in Linux

The fd command offers a simple, intuitive way to search your Linux filesystem.
296 readers like this.
How to find files in Linux

Lewis Cowles, CC BY-SA 4.0

fd is a super fast, Rust-based alternative to the Unix/Linux find command. It does not mirror all of find's powerful functionality; however, it does provide just enough features to cover 80% of the use cases you might run into. Features like a well thought-out and convenient syntax, colorized output, smart case, regular expressions, and parallel command execution make fd a more than capable successor.

Installation

Head over the fd GitHub page and check out the section on installation. It covers how to install the application on macOS, Debian/Ubuntu, Red Hat, and Arch Linux. Once installed, you can get a complete overview of all available command-line options by running fd -h for concise help, or fd --help for more detailed help.

Simple search

fd is designed to help you easily find files and folders in your operating system's filesystem. The simplest search you can perform is to run fd with a single argument, that argument being whatever it is that you're searching for. For example, let's assume that you want to find a Markdown document that has the word services as part of the filename:

$ fd services
downloads/services.md

If called with just a single argument, fd searches the current directory recursively for any files and/or directories that match your argument. The equivalent search using the built-in find command looks something like this:

$ find . -name 'services'
downloads/services.md

As you can see, fd is much simpler and requires less typing. Getting more done with less typing is always a win in my book.

Files and folders

You can restrict your search to files or directories by using the -t argument, followed by the letter that represents what you want to search for. For example, to find all files in the current directory that have services in the filename, you would use:

$ fd -tf services
downloads/services.md

And to find all directories in the current directory that have services in the filename:

$ fd -td services
applications/services
library/services

How about listing all documents with the .md extension in the current folder?

$ fd .md
administration/administration.md
development/elixir/elixir_install.md
readme.md
sidebar.md
linux.md

As you can see from the output, fd not only found and listed files from the current folder, but it also found files in subfolders. Pretty neat. You can even search for hidden files using the -H argument:

fd -H sessions .
.bash_sessions

Specifying a directory

If you want to search a specific directory, the name of the directory can be given as a second argument to fd:

$ fd passwd /etc
/etc/default/passwd
/etc/pam.d/passwd
/etc/passwd

In this example, we're telling fd that we want to search for all instances of the word passwd in the etc directory.

Global searches

What if you know part of the filename but not the folder? Let's say you downloaded a book on Linux network administration but you have no idea where it was saved. No problem:

fd Administration /
/Users/pmullins/Documents/Books/Linux/Mastering Linux Network Administration.epub

Wrapping up

The fd utility is an excellent replacement for the find command, and I'm sure you'll find it just as useful as I do. To learn more about the command, simply explore the rather extensive man page.

Tags
User profile image.
Hello! I'm Patrick, and I'm a retired IT Engineer, former IBMer, Writer, Open Source advocate, Gamer, and self-proclaimed super geek. I'm also big into space technologies and exploration, UNIX, the command-line, retro consoles, and retro computers like the Atari 2600, Commodore 64, and the Amiga.

9 Comments

Nice. That's what I was looking for. Thank you :)

Nice find.. Super fast and of course in Arch

"find . -name 'services'" will return files named "services" but not "services.md". To get the latter you'd need "find . -name 'services*'".

It looks like a great tool. I’ll give it a try. Thanks for sharing!

How about xargs integration? Is there anything like -print0?

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.