locate command search very quickly, because locate does not search the files on disk rather it searches for file paths in a database. The locate database file is located at:
[root@localhost test]# locate mlocate.db
/usr/share/man/man5/mlocate.db.5.gz
/var/lib/mlocate/mlocate.db/var/lib/mlocate/mlocate.db.UY1Pjl
[root@localhost test]#
[root@localhost test]# locate sysctl.conf
/etc/sysctl.conf
/etc/sysctl.d/99-sysctl.conf
/usr/share/man/man5/sysctl.conf.5.gz
[root@localhost test]#
Now create a directory and touch a file
[root@localhost Desktop]# mkdir -p /root/test
[root@localhost Desktop]# touch /root/test/saidrasel.lst
[root@localhost test]# locate saidrasel*
Now execute the locate command to find "saidrasel.lst" file but could'nt get
[root@localhost test]# locate saidrasel.lst
Now execute the updatedb command, it scans the whole system and updates the mlocate.db database file.
[root@localhost test]# updatedb
[root@localhost test]# locate saidrasel.lst
/root/test/saidrasel.lst
[root@localhost test]#
Note: So the limitation of the "locate" command is its dependency on the database which can be updated by another utility "updated". Hence, in order to get the latest and reliable results from "locate" command the database on which it works should be updated at regular intervals.
[root@localhost test]# locate mlocate.db
/usr/share/man/man5/mlocate.db.5.gz
/var/lib/mlocate/mlocate.db/var/lib/mlocate/mlocate.db.UY1Pjl
[root@localhost test]#
[root@localhost test]# locate sysctl.conf
/etc/sysctl.conf
/etc/sysctl.d/99-sysctl.conf
/usr/share/man/man5/sysctl.conf.5.gz
[root@localhost test]#
Now create a directory and touch a file
[root@localhost Desktop]# mkdir -p /root/test
[root@localhost Desktop]# touch /root/test/saidrasel.lst
[root@localhost test]# locate saidrasel*
Now execute the locate command to find "saidrasel.lst" file but could'nt get
[root@localhost test]# locate saidrasel.lst
Now execute the updatedb command, it scans the whole system and updates the mlocate.db database file.
[root@localhost test]# updatedb
[root@localhost test]# locate saidrasel.lst
/root/test/saidrasel.lst
[root@localhost test]#
Note: So the limitation of the "locate" command is its dependency on the database which can be updated by another utility "updated". Hence, in order to get the latest and reliable results from "locate" command the database on which it works should be updated at regular intervals.