Linux: ‘find’ vs ‘locate’ Quick Differences

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$ pwd
~/rao/srini$ cd rao
bash: cd: rao: No such file or directory
~/rao/srini$ cd /home/user
~$ pwd
~$ 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*

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 [file-name]$

$locate sample$

locate Vs find

  1. find needs ‘.’ dot in the command
  2. locate command does not need ‘.’ dot
  3. 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

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.