How to Install and use locate command on linux
Install and use locate command on Linux
The locate command is used to find files by their filename. The locate command is lightning fast because there is a background process that runs on your system that continuously finds new files and stores them in a database. This video covers the usage of locating command on Linux
Create a file by using the following command
root@linuxhelp:~# touch file.txt
root@linuxhelp:~# touch File.txt
Use the locate command to find the file.txt file, until update the DB the locate cant able to find the file
root@linuxhelp:~# locate file.txt
/usr/share/doc/alsa-base/driver/Procfile.txt.gz
Now update the DB by using the following command
root@linuxhelp:~# updatedb
Now find file.txt using locate command
root@linuxhelp:~# locate file.txt
/root/file.txt
/usr/share/doc/alsa-base/driver/Procfile.txt.gz
Use the -i option to find Case sensitivity
root@linuxhelp:~# locate -i file.txt
/root/File.txt
/root/file.txt
/usr/share/doc/alsa-base/driver/Procfile.txt.gz
Use the following command to list the particular directory using limit
root@linuxhelp:~# locate -l 5 passwd
/etc/passwd
/etc/passwd-
/etc/cron.daily/passwd
/etc/pam.d/chpasswd
/etc/pam.d/passwd
List out the file
root@linuxhelp:~# ls -la
total 55144
drwx------ 4 root root 4096 Jan 12 00:22 .
drwxr-xr-x 24 root root 4096 Dec 18 00:28 ..
-rw------- 1 root root 1115 Jan 12 00:21 .bash_history
-rw-r--r-- 1 root root 3106 Apr 9 2018 .bashrc
drwx------ 2 root root 4096 Aug 6 00:34 .cache
-rw-r--r-- 1 root root 0 Jan 12 00:22 file.txt
-rw-r--r-- 1 root root 0 Jan 12 00:22 File.txt
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-r--r--r-- 1 root root 56435756 Dec 18 00:59 VMwareTools-10.3.10-12406962.tar.gz
drwxr-xr-x 9 root root 4096 Feb 20 2019 vmware-tools-distrib
Remove the file.txt
root@linuxhelp:~# rm -rf file.txt
Now find the file.txt using locate command until we update the db it will show the file.txt while we use the locate command
root@linuxhelp:~# locate file.txt
/root/file.txt
/usr/share/doc/alsa-base/driver/Procfile.txt.gz
Use the following command to find the file present in the system
root@linuxhelp:~# locate -e file.txt
/usr/share/doc/alsa-base/driver/Procfile.txt.gz
This is the method to install and use locate command on Linux comes to end
Comments ( 0 )
No comments available