|
|
|
|
UGU: Unix Guru Universe - Unix Tip #4596- October 10, 2024
- Home : Help
: Today's Tip
Unix Tip #4596- October 10, 2024
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@glic.com
NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted
by various unix admins around the globe. UGU suggest you read and
test each tip in a non-volitile environment before placing into
production.
LAST 5 TIPS
4595
- RANDOM LINES FROM A FILE
4594
- EXTRACT THAT LAST FIELD
4593
- FULL OF FILESYSTEM INODES
4592
- FORGET THE CRONTAB MAN
4591
- POWER OF BACKQUOTES
I want to
SUBSCRIBE
and get a UGU Tip everyday.
I want to
UNSUBSCRIBE
and NOT get a UGU Tip everyday.
If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
|
|
|
Copyright 1994-2024 Unix Guru Universe |
|
|
|
|