On 22-Feb-07 Eur Ing Chris Green wrote:
While the 'locate' command is very useful at times, especially if you have lost a specific file it's much less useful when looking for, for example, a directory which has a rather common name.
E.g. I was just trying to find where I have bits of vmware installed, doing a 'locate vmware' just produces zillions of lines of output. I don't (in this case) want to know all the files which are located somewhere below a 'vmware' directory, I just want to know the location of the directory.
I know I can use an RE in locate but it's not all *that* simple to come up with an RE to do it.
I could also use 'find' which would get me exactly the result I want with a fairly straightforward command, but it would take ages.
What I really want is a 'find' that uses the locate database, I'm surprised no one has written one - or have they?
-- Chris Green
Just realised that my previous reply falls far short of giving all directories which contain a file or subdirectory with "vmware" in the name; only those where the name ends with "vmware". I think the following does better (though you still get a bit more than you bargain for):
for i in `locate vmware` ; do if [ -d $i ] ; then echo $i ; fi ; done | sort -u
/etc/vmware /etc/vmware/state /etc/vmware/vmnet1 /etc/vmware/vmnet1/dhcpd /etc/vmware/vmnet1/smb /etc/vmware/vmnet1/smb/private /etc/vmware/vmnet1/smb/var /etc/vmware/vmnet1/smb/var/locks /home/ted/.vmware /home/ted/vmware /home/ted/vmware/win98 /home/ted/vmware/win98B /usr/lib/vmware /usr/lib/vmware/configurator /usr/lib/vmware/floppies /usr/lib/vmware/help /usr/lib/vmware/modules /usr/lib/vmware/modules/binary /usr/lib/vmware/modules/binary/enterprise-2.2.17-14-RH7.0-update /usr/lib/vmware/modules/binary/enterprise-2.2.17-14-RH7.0-update/objects /usr/lib/vmware/modules/binary/smp-2.2.1 /usr/lib/vmware/modules/binary/smp-2.2.1/objects [...] /usr/lib/vmware/modules/binary/up-2.2.5 /usr/lib/vmware/modules/binary/up-2.2.5-15 /usr/lib/vmware/modules/binary/up-2.2.5-15/objects /usr/lib/vmware/modules/binary/up-2.2.5-22 /usr/lib/vmware/modules/binary/up-2.2.5-22/objects /usr/lib/vmware/modules/binary/up-2.2.5/objects /usr/lib/vmware/modules/binary/up-2.2.9-19mdk /usr/lib/vmware/modules/binary/up-2.2.9-19mdk/objects /usr/lib/vmware/modules/binary/up-2.4.0.SuSE-7.1 /usr/lib/vmware/modules/binary/up-2.4.0.SuSE-7.1/objects /usr/lib/vmware/modules/binary/up-2.4.2-2-RH7.1 /usr/lib/vmware/modules/binary/up-2.4.2-2-RH7.1/objects /usr/lib/vmware/modules/binary/up-2.4.3-20mdk-8.0 /usr/lib/vmware/modules/binary/up-2.4.3-20mdk-8.0/objects /usr/lib/vmware/modules/source /usr/lib/vmware/smb /usr/lib/vmware/smb/codepages /usr/lib/vmware/xkeymap /usr/share/doc/vmware
[125 lines in all]
For instance, /usr/lib/vmware/smb contains only the subdirectory /usr/lib/vmware/smb/codepages, so that output is superfluous. However, testing for that situation is more complicated ...
Hmmm... Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Feb-07 Time: 12:01:55 ------------------------------ XFMail ------------------------------