[olug] Unix Tip: FINDING A STRING
Unix Guru Universe
listserv at ugu.com
Tue Nov 19 19:02:43 UTC 2002
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 2149 - November 19, 2002
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FINDING A STRING
How to find a string somewhere on the system. Many times we are
called to search for a string, but we have no idea where it may
be lurking. Judicious use of the find and grep commands will
make you a hero with your co-workers.
# find . -type f -exec grep "string or options" /dev/null {} \;
Normally using only:
# find . -type f -exec grep "string/options" {} \;
Produces the target string, but you will have no clue as to where
it is located, making this almost as frustrating as using windoze!
Remember when grep'ing against multiple files the filename will be
listed before the match.
$ grep there *
foo:I found the target here
bar:You are there
In our find command we use /dev/null as a file to search against, since
we know the search will always fail if the string is found in "{}" there
filename is printed. To borrow from a famous quote:
"Pretty tricky sis!"
This tip generously supported by: james_b_horwath at glic.com
--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today
==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.
Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
==========================================================================
More information about the OLUG
mailing list