how to use locate command with its examples

  • About locate : To find files by names
  • It comes from “mlocate-0.22.2” package.
  • Configuration Files:
  • Path: /usr/bin/locate

Examples:

1. To locate any file

$ locate file.txt

2. To match only the basename against the pattern

$ locate -b file.txt
$ locate –basename file.txt 

3. To get the counts for matching entries

$ locate -c file.txt
$ locate –count file.txt 

4. To replace the default database with given

$ locate -d 
$ locate –database  

5. To print the entries those exist at the time when locate was fired.

$ locate -e filename
$ locate –existing filename
 

6. To follow trailing symbolix links

$ locate -L text
$ locate –follow text 

7. To get the locate help

$ locate -h
$ locate –help 

8. To exit successfully after finding specified number of entries.

$ locate -l 10 text
$ locate -n 10 text
$ locate –limit 10 text

9. To avoid following symbolic links

$ locate -P text
$ locate –nofollow text
$ locate -H text 

10. To seperate the output entries by ASCI NULL character

$ locate -0 text
$ locate –null text 

11. To get the statistices about the read database

$ locate -S text
$ locate –statistics text 

12. To suppress any errors if occurred

$ locate -q text
$ locate –quiet text 

13. To get the version info

$ locate -V
$ locate –version 

14. To match the whole pathname

$ locate -w text
$ locate –wholename text 

Related Commands: updatedb 

Leave a Reply

Your email address will not be published. Required fields are marked *