Search (Locate n Find Command)

Search (Locate and Find Command)

In Linux we can use Locate and Find command to search file or directory or content of the file. 

  1. locate— The locate command is used to locate a file in a Linux system, just like the search command in Windows. This command is useful when you don’t know where a file is saved or the actual name of the file. Using the -i argument with the command helps to ignore the case. So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux system containing the word “hello” when you type in “locate -i hello”. If you remember two words, you can separate them using an asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate -i *hello*this”

Locate maintain database of files (mlocate.db).

/var/lib/mlocate/mlocate.db

The database can be updated using updatedb.

Review Your Locate Database

2. Find: Search in the real system and it slower. Also has option to search using size, modification time etc.

$ find [where to start searching from] [expression determines what to find] [-options] [what to find]

find . –iname testfile.txt   – Find a file called testfile.txt in current and sub-directories.

find /home –iname *.jpg   – Find all .jpg files in the /home and its sub-directories.

Leave Comment

Your email address will not be published.