I am sharing quick differences between find and locate. If you look at the usage of commands is a little different. The given examples help you get differences and usage as well.
How to use find command.
You need to use ‘.’ after the ‘find’ to do a complete search in the current and its sub-directories. Read more on how to use find command.
~$ 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*
How to use ‘sed’ and ‘awk’ commands in Linux
How to ‘save’ and ‘exit’ top vi editor commands
12 Top Python Interview Questions
How to use locate command.
Usually, ‘mlocate is not installed by default in most Linux systems. What you can do is you can install ‘mlocate’ using the command. Read more on 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 Vs find
- find needs ‘.’ dot in the command
- locate command does not need ‘.’ dot
- compared to ‘find’ the ‘locate’ is an advanced search option. You can do with locate:
- limit the search results
- find deleted files
- count the search results