Tags:
create new tag
, view all tags
locate is a Linux search utility that searches for strings in files and paths stored in a database. That database is usually created (or at least updated) by updatedb. There is a secure version of locate known as slocate. I'm not sure what security it provides. slocate is often given the alias locate.

Also, updatedb is an alias for (or link to) locate (or slocate) -u

As I want to maintain more than one locate database (like one for general stuff, and separate ones for the X and AbiWord source code), it's time to hit the man pages and make some notes.

Many things on this page copied verbatim from the man pages for updatedb and slocate.

See:

Contents

Notes

Strategy for Multiple locate Databases

There are at least a few alternatives:

  • Issuing complete command line commands for each updatedb or locate
  • Create some wrappers, like Xlocate, Xupdatedb, Abilocate, and Abiupdatedb
  • Take advantage of the updatedb.conf file
  • Create an updatedb wrapper that updates all the locate databases
  • Where to put the other (X and Abi, for now) databases -- in, for example, /xdev (and /abidev) or with alternate names in /var/lib/slocate/slocate.db

Without discussing my reasoning (or maybe just based on gut feel), I think I want to do this:

  • Create wrappers, as described above
  • Consider using the updatedb.conf file (and some others, like Xupdatedb.conf) -- the updatedb makes it easier to exclude some directories and similar
  • Put the other databases in, e.g., /xdev and /abidev

In any case, I probably want to modify the existing updatedb.conf so it does not index /xdev and /abidev.

Creating the Command Wrappers

Modify Existing updatedb.conf to exclude /xdev and /abidev

Xupdatedb

It looks like (based on the man page) updatedb does not have the -o option, or something similar to specify which database to create / update, so I'll have to use the locate command within this wrapper.

Aside: Does updatedb (or locate) create a new database from scratch each time it is run, or does it really "update" the existing database? (I (and anybody, I think) want any deleted files to not be in the index, and recreating the index from scratch seems like the simplest way to accomplish this.)

One more -- just a guess on security -- maybe if you specify security, a given user can only find files for which he has read permission (whether because he's the owner, a member of the group, or the file is readable by all)

A first shot -- more to do when I get back to a Linux box:

slocate -e / -f NFS,... -l 0  [-c]  -U /xdev -o /xdev/slocate.db

Xlocate

A first shot -- more to do when I get back to a Linux box:

slocate -qi -d /xdev/slocate.db

And now I need to refresh my memory on how to pass a command line parameter from the wrapper to the command -- is it something like $1 (like dos?).

Yes -- see Very Simple Bash Scripts, item 6. Perhaps see also comp.unix.shell: Re: Bash question.

Ohh, and if it's a regular expression I need to pass the -r switch, and similarly -i for case insensitive, -q for quiet mode -- others?? Maybe I need to allow many things on the wrapper's command line and pass them to the wrapped command?

Abiupdatedb

Abilocate

Files and Paths

  • A configuration file for updatedb is at /etc/updatedb.conf (at least in Mandrake 9.0) -- reading it is instructive (and it's short)

  • The default location of the updatedb database is /var/lib/slocate/slocate.db (at least in Mandrake 9.0)

updatedb

updatedb  [-u] [-u path] [-e path1,path2,...] [-f fstype1,...] [-l [01]] [-q] [-v,--verbose] [-V, --version] [-h, --help] pattern...

-u
Create slocate database starting at path /.

-U <dir>
Create slocate database starting at path .

-e <dir1,dir2,...>
Exclude directories from the slocate database.

-f <fstype1,...>
Exclude files on specific file systems from the slocate database.

-c
Parse '/etc/updatedb.conf' when updating the slocate database.

-l <level>
Security level. 0 turns security checks off. This will make searchs faster. 1 turns security checks on. This is the default.

locate

slocate [-qi] [-d <path>] [--database=<path>] <search string>

slocate [-i] [-r <regexp>] [--regexp=<regexp>]

slocate    [-qv]    [-o    <file>]    [--output=<file>]

slocate   [-e <dir1,dir2,...>] [-f <fstype1,...>] <[-l  <level>]  [-c]  <[-U  <path>] [-u]>

slocate [-Vh] [--version] [--help]

-u
Create slocate database starting at path /.

-U <dir>
Create slocate database starting at path .

-e <dir1,dir2,...>
Exclude directories from the slocate database.

-f <fstype1,...>
Exclude files on specific file systems from the slocate database.

-c
Parse '/etc/updatedb.conf' when updating the slocate database.

-l <level>
Security level. 0 turns security checks off. This will make searchs faster. 1 turns security checks on. This is the default.

-i
Does a case insensitive search.

-q
Quiet mode. Error messages are suppressed.

-n <num>
Limit the amount of results shown to .

-r <regexp>  --regexp=<regexp>
Search the database using a basic POSIX regular expression.

-o <file>  --output=
Specfies the database to create.

-d <path>  --database= Specfies the path of databases to search in.

-h  --help
Display this help.

-v  --verbose
Verbose mode. Display files when creating database.

-V  --version
Display version.

Contributors

  • () RandyKramer - 08 Apr 2003
  • If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.

Page Ratings

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2003-04-08 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look