LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-18-2010, 06:04 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Using locate.


GNU/linux 2.6, slackware 12.0

Hi:
I want to print, using locate, all the paths that contain the element /bin/ but only one instance of each one. If I issue 'locate /bin/' then I have many screens of text with, for example,
/usr/bin/foo1
/usr/bin/foo2
/home/me/bin/foo3
whereas I want to see only
/usr/bin/foo1
/home/bin/foo3

That is to say, if in two lines /bin/ appears with the same prefix (in the example above the prefixes would be /usr and /home/me) I only want to print the first line.

Can I pipe locate to grep to do this? I've mentioned locate because it does not scan the whole disk.
Thanks in advance.
 
Old 06-18-2010, 06:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Not sure how to do this with locate (without multiple pipes), but find can.

find / -type d -name "bin"

This will also pick up the sbin directories, if those are not wanted/needed add: | grep -v "sbin"

Hope this helps.
 
1 members found this post helpful.
Old 06-18-2010, 06:18 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Unbelievable! It's a lot of time but I won't be doing this more than once. Thank you so much, druuna. Regards.
 
Old 06-18-2010, 06:21 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
Old 06-18-2010, 06:22 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
As stated, locate doesn't (atthe time) scan the disk - but locate also accepts regex. You an reduce the output mightily using that.
 
1 members found this post helpful.
Old 06-18-2010, 06:45 AM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thank you, cyg00.
 
  


Reply

Tags
locate



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
locate mikeshn Linux - Software 4 05-14-2007 04:38 AM
cpan> locate -u Unknown shell command 'locate -u'. Type ? for help. sharad2005 Linux From Scratch 1 08-04-2006 12:40 AM
locate juanb Linux - Newbie 2 12-18-2003 05:36 AM
Can't locate locate hindenbergbaby Linux - Newbie 3 10-22-2003 04:13 PM
how to locate ? jamaso Linux - General 4 10-17-2002 03:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration