|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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"? |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > locate and grep command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|