How to find files on CentOS 8 from the command line

Finding files on any operating system is a very common task as there are multiple files on your system at the same time. GUI based methods are available for every operating system, however on Linux I mostly prefer the CLI based methods. Therefore, today we will explore two of the easiest methods to find files in CentOS 8.

Finding Files in CentOS 8

There are two main methods used to find files in CentOS 8, which are described below:

Method # 1: Find files in CentOS 8 using the “locate” command:

The first method we’re going to follow is based on using the “locate” command to find files in CentOS 8. You just need to follow these steps:

Step # 1: Install “mlocate” utility on CentOS 8:

Sometimes using the “locate” command in CentOS 8 directly can cause some errors because this command is usually not installed by default on your system. In such a situation, we will first install the utility containing this command. It is known as the “mlocate” utility and can be installed by running the command shown below:

sudo dnf install mlocate

In our case, we already had the “mlocate” utility installed on our CentOS 8 system, so we received the following “Do nothing” messages on the terminal.

Step # 2: Update your CentOS 8 system database:

After installing any new utility on CentOS 8, it is imperative to update your system’s database using the command shown below:

sudo updatedb

If the upgrade process succeeds on your CentOS 8 system, you will not see any output on the screen.

Step # 3: Find the required file using the “locate” command in CentOS 8:

After successfully installing the “mlocate” utility and updating the file index database, we can easily use the “locate” command to locate any desired file in CentOS 8, as shown below:

locate FileName

Replace FileName with the name of the file you want to locate using the locate command. In our case, it was TestFile.txt.

Find the file using locate command

If the specified file exists on your system, then executing the above command will return the full path to that file as output, as shown in the following image:

Find a team.

Method # 2: Find files in CentOS 8 using the “find” command:

The second method we’re going to follow is based on using the “find” command to find files on CentOS 8. You just need to do the following:

Since the “find” command exists by default on our CentOS 8 system, we can simply use it right now to find the file we want, as shown below:

find -name FileName

Replace FileName with the name of the file you want to find with the “find” command. In our case, it was TestFile.txt.

Linux search command

If the specified file exists on your system, then executing the above command will return the full path to that file as output as shown in the following image. Here “.” and “/” characters in front of the file name in the output of this command indicate that the specified file is in the home directory. If it was located elsewhere, then this path will be returned as the result of this command.

Using find on Linux

Conclusion

With the help of today’s article, you will immediately learn how easy it is to find any desired file in CentOS 8 using the described methods. Now you can conveniently search for any file in CentOS 8 at any time.

How to find files on CentOS 8 from the command line

Sidebar