Looking for a Simple and Fast Alternative to Find Command? | The fd command in Linux

Usually when you search for a file in the system, you do it using a file browser, but what if you want to use the terminal? Well, there is a command called find that does the job, but there is a better alternative. Today, we will talk about the fd command on Linux.

Introduction

According to the GitHub website where the source code of the tool is hosted

fd is a program to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find. While it does not aim to support all of find’s powerful functionality, it provides sensible (opinionated) defaults for a majority of use cases.

Although it does not have so many features, it accomplishes the task at hand and is easy to use. This is the main focus of it.

The tool is created in Rust, so it is quite light and practical to install, and you will be able to run it in almost any Linux distribution.

Some main features of it are:

  • Intuitive syntax: fd PATTERN instead of find -iname ‘PATTERN‘.
  • Regular expression (default) and glob-based patterns.
  • Very fast due to parallelized directory traversal.
  • Uses colors to highlight different file types (same as ls).
  • Supports parallel command execution
  • Smart case: the search is case-insensitive by default. It switches to case-sensitive if the pattern contains an uppercase character*.
  • Ignores hidden directories and files, by default.
  • Ignores patterns from your .gitignore, by default.

As you can see, there are quite a few new features to be a worthy alternative to the find command.

Let’s get started.

Installing the fd command on Linux

The fd command is present in most Linux distributions by default; however, you can also compile the source code yourself if you already have Rust.

For Debian and Ubuntu-based distributions,

sudo apt update
sudo apt install fd-find

If you use Fedora, RHEL or derivatives like CentOS, Rocky Linux, Alma Linux and so on:

 sudo dnf install fd-find

On Arch Linux and Manjaro

sudo pacman -S fd

And finally for openSUSE:

sudo zypper in fd

Now you can continue.

Using the fd command on Linux

The normal thing to do is to start by showing the help that the command itself provides. To achieve this, run.

fdfind --help
fd help
fd help

There, you can see useful information about the command itself, such as options and usage modes.

Examples on the use of the fd command

To search for a file in the current directory at the prompt, you can use the following syntax

fdfind [name]
Using the fd command in Linux
Using the fd command in Linux

On the output screen, you will see the list of results, and you will notice how the directories are colored blue to make the output more readable.

You can also do more advanced searches using regular expressions. For this, you also have to add the -g option. For example:

fdfind 'imagine*.md' -g

This will search for all files starting with the word imagine and having the extension md.

By default, the command does not do recursive searches within the directory. That is, if the search starts in the /home/user/ folder, it will also affect the subdirectories.

But you can also specify the directory where to do the search:

fdfind imaginelinux /home/user/Downloads

So, you have to set the name or search criteria first and then the directory.

By adding the -H option, you can limit the search to hidden files only

fdfind -H example

Or to do a search by extension, use the -e option

fdfind -e md

This will search for all md files in the current folder.

If you want to search for a single particular file, you should use the -g option again.

fdfind -g [name] [folder]

Although, you may not include the folder to search in the current directory.

Uninstalling the fd on Linux command

If you don’t plan to use it anymore, then you can remove it from the system. The process will depend on your distribution.

For Debian, Ubuntu and family

sudo apt remove fd-find

For Fedora and company

sudo dnf install fd-find

Arch Linux and Manjaro

sudo pacman -R fd

And for OpenSUSE

sudo zypper rm fd

As you can see, it is similar to the installation.

Conclusion

The fd command turns out to be a real alternative to the find command. It is simple to install and use and although it has fewer functions, the ones it has are easy to use.

I hope you liked this post and help us grow by sharing it.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top