How to Find Files in CentOS 8





There are many tools in the arsenal of a Linux system administrator for finding files and directories. It actually searches through a directory hierarchy for files and directories according to a given expression and can perform the action that the user specifies for the matched files. Locate is a Unix program that locates files on filesystems. Searches a database of files built by updating the database with the updatedb command or by using a daemon that compresses files with incremental encoding. The operation is significantly faster than “find”, but the database must be updated regularly to maintain its effectiveness.






In this tutorial, we will learn how to locate a file using the ‘locate’ and ‘find’ commands.  







  • Searching for Files using “locate” Command:





Step 1: Install the “mlocate” Utility







Sometimes errors will occur because this command is generally not installed by default on your system, so the utility must be installed first.


Run the following command:




# sudo dnf install mlocate






Step 2: Update your System Database





Run the following command,




# sudo updatedb







Step 3: Use “locate” to locate the file that you need.




Now, you can find the files by using the locate command, In this case, we have used ‘yourfilename‘ instead of the actual file name. Feel free to change it with the actual one.




# locate yourfilename




For example,


[[email protected] ~]# locate file1




That’s it!







  • Searching for Files using “find” Command:





CentOS comes with the find command by default, so we can use it directly. Replace the filename with yours when executing the following command.


# find -name yourfilename




Find an empty file within the current directory by running the following command.



# find . -type f -empty




Using the following command, search for all .jpg files under /home and its subdirectories. Replace /home with the name of the directory you want to search.



# find /home -name *.jpg






That’s it, Thanks for reading! I hope it was informative for you! 







Try VPSie for free today!