UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 1st, 2005, 10:52 PM
Basil_Fawlty Basil_Fawlty is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 16 Basil_Fawlty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 7 m 7 sec
Reputation Power: 0
locate and grep command

If I wanted to locate all filenames that contain the word "emacs" would this be right?

locate *emacs*

Also how would I combine this with grep to avoid displaying all filenames containing the world "lib"?

Reply With Quote
  #2  
Old March 2nd, 2005, 07:25 AM
thong_yw thong_yw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 thong_yw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 57 sec
Reputation Power: 0
you can try this

ls -l | grep "*emacs*"
or
ls -l | grep "\*emacs\*"

I am not too sure of which bcos i am not in front of a unix machine at the moment. as to how not to select with the word "lib" i have no idea.

Reply With Quote
  #3  
Old March 2nd, 2005, 12:06 PM
bingotailspin's Avatar
bingotailspin bingotailspin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 115 bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 52 m 45 sec
Reputation Power: 7
find . -name *emacs* |grep -v lib

The find command work work recursively from the current directory. If you don't want to search current directory, replace . with the directory you want to search.

Reply With Quote
  #4  
Old March 2nd, 2005, 01:46 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
thong_yw please note: on *nix
ls -l | grep "*emacs*"
or
ls -l | grep "\*emacs\*"
AND
ls -l ¦ grep emacs
GIVE all the same result!
save (useless && confusing) keystrokes
btw: why -l in ls ?

bingotailspin
you need quotes around *emacs* in find
and if you anyway use find¦grep, this is also a version:
find . ¦ grep emacs |grep -v lib

Basil_Fawlty
'locate' is not a standard Unix tool, i dont believe it supports '*'
the unix cmd are: 'which' (and 'type' on ksh) used to LOCATE
filenames in $PATH

my suggestion

find .¦ sed -n '/lib/d;/emacs/p'
have fun
__________________
working on Solaris[5-9], preferred languages french and C.

Reply With Quote
  #5  
Old March 2nd, 2005, 03:54 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 54 m 7 sec
Reputation Power: 797
One more problem with locate is that it uses a database rather than searching the directories for a file. Also, the database it uses is updated by a cron job (runs daily on some distros of linux and weekly on openbsd). Thus, it is possible to delete a file and locate will still claim that it exists, since its database hasn't been updated yet.

I would use find because it looks in all directories, not just the directories in the path.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > locate and grep command


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway