Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: bakedjake

Message Too Old, No Replies

Linux locate bug

     

joecarter

5:44 pm on Mar 16, 2010 (gmt 0)

5+ Year Member



I am new to Linux and am running a Centos 5 distribution to get up to speed. One thing which I have found extremely frustrating on the first day is the inconsistencies with a simple command like "locate". See the commands below with OK! for success and FAILED! for the inconsistency ... :

[root@localhost /]# locate "*mware-config*.pl"
/usr/bin/vmware-config-tools.pl
OK !
[root@localhost /]# locate "*mware-config*"
/usr/bin/vmware-config-tools.pl
OK !
[root@localhost /]# locate "*mware-config-tool*.pl"
/usr/bin/vmware-config-tools.pl
OK !

[root@localhost /]# locate "vmware*.pl"
FAILS!
[root@localhost /]# locate "vmware*"
FAILS!
[root@localhost /]# locate "vmware-config*.pl"
FAILS!
[root@localhost /]# locate "vmware-config-*.pl"
FAILS!


This is UTTERLY INCONSISTENT! Why does the trailing * wildcard not deliver the file ? Much appreciated if anyone can assist :-)

lammert

12:31 am on Mar 17, 2010 (gmt 0)

WebmasterWorld Senior Member lammert is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



First of all a warm welcome to WebmasterWorld joecarter!

Locate doesn't find files based on their basename, but based on their full path stored in a local database which is periodically compiled with the updatedb task. The regular expression parameter you pass to the locate tool must match a whole line in the database. vmware*.pl doesn't match any of the entries, because they are all full paths beginning with a slash. Therefore a wildcard at the beginning is necessary. It matches the path part of the file location.

You can also use real-time searching where you can specify a basename only. For example:

find / -name "vmware*.pl" -print

This command performs a search through the whole directory structure instead of a precompiled database and will therefore take more time than a search with the locate utility.

joecarter

1:44 pm on Mar 17, 2010 (gmt 0)

5+ Year Member



Thanks Lammert. This is crystal clear.
Nice would be if was this clear in the "man" online :-)

phranque

1:48 pm on Mar 17, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



this might also help.
from the man page:
whereis locates source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in a list of standard Linux places.

lammert

8:11 pm on Mar 17, 2010 (gmt 0)

WebmasterWorld Senior Member lammert is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The problem with whereis is, that it was desigined in the old Unix times when disk access was a time consuming operation. It therefore only searches in some default system paths like /bin, /etc and /usr/*. Files in one of the user directories or in an application specific directory can't be found with whereis.

phranque

9:12 pm on Mar 17, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



it's not a problem - just one more tool in the bag.
i've been on servers where one or the other is not installed or the path where one is located is not specified in $PATH so you can sometimes use another one instead of or to find the other.

joecarter

1:17 pm on Mar 18, 2010 (gmt 0)

5+ Year Member



Thanks all. I must say after jsut trying the whereis cmd I find it unclear too (which is how this thread started). if I type whereis 'Red Hat-release' I get a response:
Red Hat-release:
on the next line. what does this mean .. well actually it means the file is not there ... pretty unusable feedback!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month