Need unix command file HELP!
Steve Summit
stevesu at copper.UUCP
Tue Feb 18 12:59:22 AEST 1986
In article <245 at aero.ARPA>, sutton at aero.ARPA (Stew Sutton) writes:
> We are looking for a utility that can, when given a arbitrary string,
> can locate all occurences of that string anywhere on the system. Our
> local Un*x gurus can't figure this out, so we are appealing to those out
> in Netland to help us out.
Stew's question has basically been answered, but I've got two
cents to add:
1. Since such a command is probably going to generate
voluminous output, it is tempting to redirect it to a
file for later perusal. If you do so, be extremely
careful: if your program is searching the entire
filesystem, it is likely to find your output file,
each of whose lines contains the string you're looking
for, and which will therefore get re-appended to the
file, ad infinitum...
I make this mistake every few years, filling up a disk
every time. If you don't need to search the entire
filesystem, just make sure you put the output file
somewhere where it won't get found, like /tmp. The
general solution would be an exclusion option on the
find command, which would be generally useful.
(Another trick would be to make the output file
unreadable.)
2. Joe Yao pointed out the problem of the grep family not
printing the filename if given a single argument. My
solution, which is a bit wasteful, but probably more
efficient than Joe's shell script, goes like this:
find / -exec grep 'little dog' {} /dev/null \;
grep notices two arguments, so cheerfully prints the
filename if it finds the string, although it's
virtually guaranteed never to occur in the second one
(unless /dev/null accidentally got replaced with a
real file, but that's another story).
Steve Summit
tektronix!copper!stevesu
More information about the Comp.unix.wizards
mailing list