This article is a comparison between locate and find commands in Linux systems.
find vs locate Command
In Linux systems, find and locate commands are useful and they are used for a similar purpose to search for a file in the system. Though their purpose is similar they use different methodologies for finding the files.
The following are the difference between the find and locate commands in Linux:
Find Command | Locate Command |
---|---|
It finds the file in the filesystem | It finds the file in the database |
It is a little slow as compared to locate | locate is much faster the Find |
The data is accurate | The data is sometimes not accurate |
It performs real-time scanning | Find files in mlocate database |
It is installed on the Linux by default | It must be installed using the package manager |
It has a complicate syntax | locate command has the simple syntax |
Find the Files Using the find Command in Linux
The find command searches the files based on the size, permission, type, group, time, and date. The following is the general syntax of the command:
Search a file in a Linux with the files name using the following command:
To find a directory using the find command, run the following command in the terminal:
Execute the following find command to search for the empty files and directories:
Find the Files Using the locate Command in Linux
The locate command depends on the mlocate database if the database is not updated, it will not work properly. The usage of locate command is easy. You have to install it on your system via the following command:
If the command is not working then update the installed database by executing the following command:
Once the update is finished, use the following syntax to search the file in Linux:
Here I am searching the filename.wav:
Use the -r operator with the locate command to get the exact match of the file:
Bottom Line
The locate and find commands are popular and come in handy. The locate command is helpful in searching files quickly and uses the database to search the files on the disk so it must be updated to work properly. The find command is more powerful but it takes a long time to search the files in the filesystem. It has several options and is more configurable.