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$ cd rao
bash: cd: rao: No such file or directory
~/rao/srini$ cd /home/user
~$ 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*
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.
Differences Between Locate and Find
- find needs ‘.’ dot in the command
- locate command does not need ‘.’ dot
- You can do with locate:
- limit the search results
- find deleted files
- count the search results