Friday, March 29, 2024
HomeA-Z CommandsHow To Use the fd Command on Linux System

How To Use the fd Command on Linux System

In Linux, there is a dedicated “find command” for finding values and strings on the command, directory, or inside a script. But the dedicated find command might not be useful all the time. In most cases, the Linux and Unix-like OS users find the fd command most efficient and useful for finding values. Originally, the fd was a separate program for Linux that could look for files on the entire filesystem.

In the search result, the fd command provides you a PID, file location directory, file type, file size, and many more. If you’ve been looking for a better way to find files on Linux, you can try the fd command for better and smoother search results.

fd Command on Linux


All types of regular search, searching on the home or root directory, and other conventional search queries can be performed through the fd command. The format and patterns of the fd command are easy and hassle-free to learn. The installation and using method of the fd command are pretty much easy and self-explanatory. It’s already available on the official Linux repository.

As the Linux developers have created the fd command despite having the traditional find command, it’s urgent to know what is the difference between the find and fd commands. We will also need to know what features the fd command has. In this post, we will see the difference between find and fd, installation, and the using method of fd on Linux.

1. fd vs Find Command on Linux


You might have been wondering about what is the main difference between the fd and find command on Linux? The main purpose of introducing the fd command on Linux is not to replace the Find command. The traditional Find command is useful, and it has its conventional syntaxes with different use-cases.

The main reason for inventing the efficient fd command was to make the finding procedures more straightforward and hassle-free. It has been seen that the Fd command is much faster than the conventional Find command.

The Fd command can find files and objects in an extensive way and color the outputs if the user wants. The Fd repository and user manuals are already available on the Github repository. You can maintain search patterns via the fd command on Linux. While using the fd command, you just need to pay extra attention to the uppercase and lowercase syntaxes because the fd command is case-sensitive.

2. Features of fd Command on Linux


Before we go to the installation process and the examples, we must know the basic features of the fd command. Here, I’ve enlisted the most used and important features of fd command.

- -
  • The syntaxes of the fd command are very self-explanatory and easy to understand.
  • You can use different colors to highlight the search results and the directories.
  • The fd command is case-sensitive.
  • It can look inside the directories and subdirectories
  • You can use the fd command to run other executable applications
  • You can define specific file names and directories for search.
  • By default, the fd command does not look for files inside the hidden directories.

3. Installing fd Command on Linux


The process of installing the fd command is easy and not a complex task. In the most recent updated Linux distributions, the fd command comes preinstalled with the operating system. However, if you can not execute the fd command on your terminal shell, please run the following commands on the terminal shell with root access according to your distribution.

Install fd tool on Ubuntu

sudo apt-get install fd-find

install fd command on Linux

Get the fd command for Fedora and Red Hat Linux

sudo dfn install fd-find

Install fd on Arch and Arch-based Linux system

sudo pacman -Syu fd

When the installation is done, you may now check the version of the fd command tool on your system. Here, we are keeping the fd command as fdfind to make the commands easy to understand. To make that, we will run the below alias fdfind command on the terminal shell. Later, we can use the fd command.

alias fd=fdfind

After installing the fd tool, you can now check the fd version on your machine.

fd version and alias

fdfind --version

4. Search with fd on Linux


After installing, we are now ready to search files and directories through the fd command on Linux. The below-mentioned fd command will allow you to see the file types and directories on your current filesystem location.

fdfind

To find all the PNG image files in your directory, please use the below-mentioned command on the shell.

fd find png on Linux

fdfind -e png

If you need to find a specific type of file on your system, you can execute the fd command on your terminal shell with the full file name. Here, let’s see, for instance, we are looking for a file named index.page through the fd command.

fdfind index.page

If we are looking for a file inside a directory that has a few more subdirectories as well, we do not need to tell the fd command to look for inside the sub-directories. However, we can also search inside any specific directory as well. For instance, the below-mentioned fd command will let us search inside the “etc directory” on the Linux directory.

fdfind passwd /etc

Here is a dynamic way to find files with a portion of the file name. For instance, let we want to search for C programming files that have the name UbuntuPIT in the file name. The below fd command with an -e flag will allow us to find the file name.

fdfind -e c UbuntuPIT

5. Syntaxes of fd on Linux


Here are a few basic syntaxes and flags that you might know about the fd command. We can execute the fd commands on even the empty folder.

  • f: The f flag defines the files
  • D: The d is noted as a directory
  • l: The I is used for symbolic links or soft links
  • x: The x syntax is used to find the executable files
  • e: The e is used for finding inside the empty files or directories.

The below-mentioned fd command will allow us to look for images in the directory.

fdfind -td images

As we said earlier that the fd command is case-sensitive; here, we can see how it can differentiate files based on the filename with uppercase and lowercase. The below-mentioned 2 commands are the same, except they used uppercase and lowercase file names. The resultant of these two commands will also be different.

fdfind -tf ubuntupit
fdfind -tf UbuntuPIT

6. Execute Another Application With fd


If you have a compressed or zip file on your file system and you want the fd command to look inside the zip file. In that case, in the conventional method, we might unzip or extract the file manually then we can run the fd command.

But, with the fd command, you can tell the fd tool to execute the zip commands to look inside the folder. In the same way, we can also use the fd command to run other executable programs on your Linux system through the fd command.

fdfinf -e zip

7. Find Hidden Files


Another use of the fd command for finding the hidden files on the Linux filesystem might be helpful when you need to get a file that you might have hidden accidentally or you can not remember the exact directory. The below-mentioned command will show the hidden files in the directory.

fdfind -H gitignore

8. Recursive Search with FD


When we execute the fd command with no flags or arguments or specific commands, the fd command recursively lists all the files in the directory. This argument-free command may help you to display all the files in the directory.

$ fdfind

9. Find with File Extension


The file extension is the last part of the file name that defines the file type and the behavior of the file. In Linux, if you need to call any file with the extension name, you may run the below-mentioned fd command on the terminal shell. For instance, the following command will gather all the text files.

$ fdfind -e txt

Insights


In the entire post, we have seen the installation process of the fd command and how to get started with it. We have covered a few most used fd commands, and there are many more. If you need to know anything about any specific fd syntax, you can write in the comment section. The overall user experience of the fd command will make your Linux experience smoother.

I hope this post has been helpful for you; if yes, please share this post with your friends and the Linux community. You can also let us know which tool you find most useful for finding files on your system.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

You May Like It!

Trending Now