Tuesday, March 12, 2013

Linux Locate Command With Example


ABOUT LOCATE COMMAND :-
:->> The locate command is usually the simplest and fastest way to find or search the locations of files and directories on Linux and other Unix-like operating systems.
NOTE:-   First of all Update the DataBase (Using the command updatedb )
#updatedb

The basic syntax for locate command is:-
#locate [options] name  (searching)

1  [root@station110 ~]# locate vinod
Output is :-
/home/vinod
/home/vinod/.bash_logout
/home/vinod/.bash_profile
/home/vinod/.bashrc
/home/vinod/.gnome2
/home/vinod/.mozilla
/home/vinod/.mozilla/extensions
/home/vinod/.mozilla/plugins
/root/vinod.gpg
/root/vinod.txt
/var/run/vinod.ping
/var/spool/mail/vinod

2  [root@station110 ~]# locate vinod.txt (it will locate vinod.txt file get into the system)
output :-   /root/vinod.txt

3  [root@station110 ~]# locate httpd.conf    (locate the configuration file path of httpd.conf)
/etc/httpd/conf/httpd.conf

4 [root@station110 ~]# locate tpvmlp.conf  (locate the all path of tpvmlp.conf )
/etc/tpvmlp.conf
/etc/vmware-tools/tpvmlp.conf

5 -Find(Locate) ignore-case (not a case sensitive)
[root@station110 ~]# locate htTpd.conf
[root@station110 ~]# locate -i htTpd.conf
/etc/httpd/conf/httpd.conf

6 -Using Limit to Locate the output file
[root@station110 ~]# locate -l 3 conf (it search 3 conf file it can be 30 , 100 etc.)
/boot/config-2.6.32-279.el6.x86_64
/boot/grub/grub.conf
/etc/ant.conf

7 -Find(Locate) file with full information related to it
[root@station110 ~]# locate httpd.conf | xargs ls -lah
-rw-r--r--. 1 root root 34K Feb  7  2012 /etc/httpd/conf/httpd.conf

8 -Find(Locate) 3 (.html) file
[root@station110 ~]# locate -n 3 "*.html"
/usr/lib64/eclipse/about.html
/usr/lib64/eclipse/epl-v10.html
/usr/lib64/eclipse/notice.html
                  OR
[root@station110 ~]# locate ".*html" | less
[root@station110 ~]# locate -n 2 "*.png" -q (The -q option is used to suppress error messages)
/etc/favicon.png
/root/.thumbnails/fail/gnome-thumbnail-factory/05e29bc60b9f79b9aa80c6ab93a31d00.png

______________________________________________
DIFFERENCE BETWEEN FIND AND LOCATE COMMAND:-

Both find and locate are useful commands in system administration. Both these commands can be used to search for data:
 find searches within the real system. Is slower however forever up-to-date and has a lots    of options (size, modification time,...)

 locate uses a previously built database (command updatedb). Is much faster, but uses an 'older' database and searches only names or parts of them.








No comments:

Post a Comment