Differences Between Find and Locate in Linux

Both find and locate are search commands in Linux. Here are the difference between these two.

1.How to use Find


You can use for complete search in both directory and sub-directory.

~$ mkdir rao
~$ cd rao
~/rao$ mkdir srini
~/rao$ cd srini
~/rao/srini$ vi sample
~/rao/srini$ pwd
/home/user/rao/srini
~/rao/srini$ cd rao
bash: cd: rao: No such file or directory
~/rao/srini$ cd /home/user
~$ pwd
/home/user
~$ ls
Srinimf rao
~$ find samp$
find: ‘samp$’: No such file or directory
~$ find . -name *
find: paths must precede expression: rao' find: possible unquoted pattern after predicate-name’?
~$ find -name *.txt
~$ find . -name *.txt
~$ find . -name samp*
./.snapshots/2020-08-22-132152/rao/srini/sample
./rao/srini/sample
~$

2. How to use Locate

Usually, ‘mlocate is not installed by default in most Linux systems. What you can do is you can install ‘mlocate’ using the command. Here is how to use locate command options.

sudo apt-get update
sudo apt-get install mlocate

Syntax to use locate command. You need to add dollar symbol at the end of the file-name that you are searching.

$locate [file-name]$

$locate sample$

Differences Between Locate and Find

  1. find needs ‘.’ dot in the command
  2. locate command does not need ‘.’ dot
  3. You can do with locate:
    1. limit the search results
    2. find deleted files
    3. count the search results

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.