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?
Hi Chris
On Thursday 22 February 2007 10:50, 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.
My first reaction was use `find`, but....
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.
A quick look at `man locate` shows that it provides many of the same options as find. If it is a directory you seek, use `-type d`, and to limit the depth of search, add `-maxdepth 3` - None of which involve gnarly regexs ;)
Regards, Paul.
On Thu, Feb 22, 2007 at 11:09:16AM +0000, Paul wrote:
Hi Chris
On Thursday 22 February 2007 10:50, 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.
My first reaction was use `find`, but....
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.
A quick look at `man locate` shows that it provides many of the same options as find. If it is a directory you seek, use `-type d`, and to limit the depth of search, add `-maxdepth 3` - None of which involve gnarly regexs ;)
Not on my locate! There's no options anything like -type or -maxdepth.
My locate is:- home$ locate -V Secure Locate 3.1 - Released March 7, 2006
What's yours?
Hi Chris
On Thursday 22 February 2007 11:28, Eur Ing Chris Green wrote:
My first reaction was use `find`, but....
Not on my locate! There's no options anything like -type or -maxdepth.
Um..err... (hangs head) I mistakenly looked at the man page for find, no wonder it looked familiar.... Please disregard earlier message and put it down to one of those Homer moments.
Regards, Paul.
On Thu, Feb 22, 2007 at 11:44:06AM +0000, Paul wrote:
Hi Chris
On Thursday 22 February 2007 11:28, Eur Ing Chris Green wrote:
My first reaction was use `find`, but....
Not on my locate! There's no options anything like -type or -maxdepth.
Um..err... (hangs head) I mistakenly looked at the man page for find, no wonder it looked familiar.... Please disregard earlier message and put it down to one of those Homer moments.
:-) :-) :-)
That's cheered me up no end!
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
The following doesn't quite do what you're looking for, since it also throws up files named "vmware" as well as directories. However, the result is compact, and is produced quite quickly. You could pipe the output through a filter which tests for "directory".
locate vmware | grep 'vmware$' | sort -u
/etc/init.d/rc3.d/K22vmware /etc/init.d/rc3.d/S01vmware /etc/init.d/vmware /etc/vmware /home/ted/.vmware /home/ted/vmware /usr/X11R6/lib/X11/sax/profile/vmware /usr/bin/vmware /usr/lib/vmware /usr/share/doc/packages/ethereal/README.vmware /usr/share/doc/susehilf/raw_pacs/en/vmware /usr/share/doc/vmware /var/lock/subsys/vmware
HTH Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Feb-07 Time: 11:21:57 ------------------------------ XFMail ------------------------------
On Thu, Feb 22, 2007 at 11:22:22AM -0000, Ted Harding wrote:
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
The following doesn't quite do what you're looking for, since it also throws up files named "vmware" as well as directories. However, the result is compact, and is produced quite quickly. You could pipe the output through a filter which tests for "directory".
locate vmware | grep 'vmware$' | sort -u
/etc/init.d/rc3.d/K22vmware /etc/init.d/rc3.d/S01vmware /etc/init.d/vmware /etc/vmware /home/ted/.vmware /home/ted/vmware /usr/X11R6/lib/X11/sax/profile/vmware /usr/bin/vmware /usr/lib/vmware /usr/share/doc/packages/ethereal/README.vmware /usr/share/doc/susehilf/raw_pacs/en/vmware /usr/share/doc/vmware /var/lock/subsys/vmware
Yes, better than nothing, thanks. However it does seem that locate is somewhat lacking in its 'emulation' of find.
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 ------------------------------
On 2/22/07, Eur Ing Chris Green cl@isbd.net 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.
If you find and locate are too scary, how about du and grep?
"du / | grep dir" will produce a tree list of all the directories on your filesystem and their sizes (not a good idea if you remote filesystems mounted) and then searches it for 'dir'.
"du -a /" does the same, but lists all files too and their block sizes.
Yeah, it's a big hack, but it searches the live filesystem rather the locate database.
Hope this helps! Tim.