[Ilugc] Tips of the day (Locate command)

  • From: vishnukraj007@xxxxxxxxx (Vishnu Raj)
  • Date: Tue Jan 19 20:40:57 2010

Looking for an easier way to find files than the find command? Try
using locate. In contrast to find's complexity, locate is the ultimate
in simplicity. The command:

locate <string>

searches an internal database and prints the pathnames of all files
and directories that contain the given string in their names. You can
narrow down the search by piping the output to grep. For example, the
following finds all files containing the string "kde" that are in bin
directories:

locate kde | grep bin

The strings don't have to be complete names; they can be partial
strings, such as "gno" instead of spelling out "gnome". The -r option
lets you use a regular expression (in quotes):

locate -r 'gno*'

One thing to be aware of is that locate is case-sensitive: Searching
for HOWTO and for howto will give you different results.

Rather than searching the disk each time, as find does, locate depends
on the creation and maintenance of a database. Because it only has to
search the database, not the disk, locate is faster than find. On the
other hand, the results are only as current as the database.

The locate database is generally updated daily by a cron job, but you
can update it manually by running the command updatedb (usually as
root). If you are adding new applications or deleting old files and
you don't want to wait for the next day to have an up-to-date
database, you might want to run it manually.

-- 
??????????. ?

Kanchi Linux User Group Rocks !

http://kanchilug.wordpress.com

My Experiments In Linux are here

http://gnutuxfollower.wordpress.com

Other related posts: