Difference between revisions of "Locate"

From ArchWiki
Jump to: navigation, search
(Created page with "{{ic|locate}} is a common Unix tool for quickly finding files by name. It offers speed improvements over the {{ic|find}} tool by searching a pre-constructed database file (sto...")
 
(+Category:File systems)
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{ic|locate}} is a common Unix tool for quickly finding files by name. It offers speed improvements over the {{ic|find}} tool by searching a pre-constructed database file (stored in {{ic|/var/lib/mlocate/mlocate.db}}), rather than the filesystem directly. The downside of this approach is that changes made since the construction of the database file cannot be detected by {{ic|locate}}. This problem is minimised by regular, typically scheduled use of the {{ic|updatedb}} command, which (as the name suggests) updates the database.
+
[[Category:Command shells]]
 +
[[Category:File systems]]
 +
[[ko:locate]]
 +
{{Lowercase_title}}
 +
 
 +
{{ic|locate}} is a common Unix tool for quickly finding files by name. It offers speed improvements over the [http://en.wikipedia.org/wiki/Find find] tool by searching a pre-constructed database file, rather than the filesystem directly. The downside of this approach is that changes made since the construction of the database file cannot be detected by {{ic|locate}}. This problem is minimised by regular, typically scheduled use of the {{ic|updatedb}} command, which (as the name suggests) updates the database.
  
 
==Installation==
 
==Installation==
 
Although in other distros {{ic|locate}} and {{ic|updatedb}} are in the {{Pkg|findutils}} package, they are no longer present in Arch's package. To use it, install the {{Pkg|mlocate}} package. mlocate is a newer implementation of the tool, but is used in exactly the same way.
 
Although in other distros {{ic|locate}} and {{ic|updatedb}} are in the {{Pkg|findutils}} package, they are no longer present in Arch's package. To use it, install the {{Pkg|mlocate}} package. mlocate is a newer implementation of the tool, but is used in exactly the same way.
  
Before {{ic|locate}} can be used, the database will need to be created. To do so, simply run {{ic|updatedb}} as root.
+
Before {{ic|locate}} can be used, the database will need to be created. To do this, simply run {{ic|updatedb}} as root.
  
 
===Keeping the database up-to-date===
 
===Keeping the database up-to-date===
You will most likely want to automate the process of regularly updating the database. [[cron]] is a common way of doing this (remember when setting up the "cron job" that updatedb must be run by root).
+
When {{ic|mlocate}} is installed, a script is automatically placed in {{ic|/etc/cron.daily}} (so that [[cron]] runs it daily) that will update the database. You can also manually run {{ic|updatedb}} at any time.
 +
 
 +
To save time, the {{ic|updatedb}} can be (and by default is) configured to ignore certain filesystems and paths by editing {{ic|/etc/updatedb.conf}}. {{ic|man updatedb.conf}} will tell you about the semantics of this file. It is worth noting that among the paths ignored in the default configuration (i.e. those in the "PRUNEPATHS" string) are {{ic|/media}} and {{ic|/mnt}}, so {{ic|locate}} may not discover files on external devices.

Revision as of 06:01, 24 March 2013

locate is a common Unix tool for quickly finding files by name. It offers speed improvements over the find tool by searching a pre-constructed database file, rather than the filesystem directly. The downside of this approach is that changes made since the construction of the database file cannot be detected by locate. This problem is minimised by regular, typically scheduled use of the updatedb command, which (as the name suggests) updates the database.

Installation

Although in other distros locate and updatedb are in the findutils package, they are no longer present in Arch's package. To use it, install the mlocate package. mlocate is a newer implementation of the tool, but is used in exactly the same way.

Before locate can be used, the database will need to be created. To do this, simply run updatedb as root.

Keeping the database up-to-date

When mlocate is installed, a script is automatically placed in /etc/cron.daily (so that cron runs it daily) that will update the database. You can also manually run updatedb at any time.

To save time, the updatedb can be (and by default is) configured to ignore certain filesystems and paths by editing /etc/updatedb.conf. man updatedb.conf will tell you about the semantics of this file. It is worth noting that among the paths ignored in the default configuration (i.e. those in the "PRUNEPATHS" string) are /media and /mnt, so locate may not discover files on external devices.