Finding files in any operating is a very common task as you have multiple files residing on your system at a time. The GUI based methods of doing so are readily available for every operating system, however, in Linux, I mostly prefer the CLI based methods. That is why today we will learn the two most simple methods of finding files in CentOS 8.

Searching for Files in CentOS 8

For finding files in CentOS 8, two basic methods are used which are described below:

Method # 1: Finding Files in CentOS 8 using the “locate” Command:

The first method that we are going to follow is based on the usage of the “locate” command for finding files in CentOS 8. You simply have to perform the following steps:

Step # 1: Install the “mlocate” Utility in CentOS 8:

At times, using the “locate” command in CentOS 8 directly might render some errors because this command is generally not installed by default on your system. In such a situation, we will first install the utility that contains this command. It is known as the “mlocate” utility and can be installed by executing the command shown below:

sudo dnf install mlocate

In our case, we already had the “mlocate” utility installed on our CentOS 8 system that is why we have received the following messages on the terminal “Nothing to do”.

Step # 2: Update your CentOS 8 System’s Database:

After installing any new utility on CentOS 8, it is mandatory to update your system’s DB with the command shown below:

sudo updatedb

Update file database

If the update process completes successfully on your CentOS 8 system, then you will not see any output on the screen.

Step # 3: Find the Desired File using the “locate” Command in CentOS 8:

After the successful installation of the “mlocate” utility and updating the file index database, we can easily use the “locate” command to find any desired file in CentOS 8 in the manner shown below:

locate FileName

Replace FileName with the name of the file to be found with the “locate” command. In our case, it was TestFile.txt.

Find a file using locate command

If the said file exists on your system, then running the above-mentioned command will return the complete path of this file as its output as shown in the following image:

Locate command.

Method # 2: Finding Files in CentOS 8 using the “find” command:

The second method that we are going to follow is based on the usage of the “find” command for finding files in CentOS 8. You simply have to do as follows:

Since the “find” command exists by default on our CentOS 8 system, therefore, we can simply use it straight away to find the desired file in the manner shown below:

find -name FileName

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

Linux find command

If the said file exists on your system, then running the above-mentioned command will return the complete path of this file as its output as shown in the following image. Here, the “.” and “/” symbols before the file name in the output of this command indicate that the specified file is located in the Home directory. If it would have been located elsewhere, then that path will be returned as an output of this command.

Using find on Linux

Conclusion

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

How to Find Files in CentOS 8 on the Command Line
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.