Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 (USS@Tek, v1.0) based on 4.3bsd-beta 6/6/85; site copper.UUCP Path: utzoo!linus!decvax!tektronix!teklds!copper!stevesu From: stevesu@copper.UUCP (Steve Summit) Newsgroups: net.unix,net.unix-wizards,net.wanted Subject: Re: Need unix command file HELP! Message-ID: <187@copper.UUCP> Date: Mon, 17-Feb-86 21:59:22 EST Article-I.D.: copper.187 Posted: Mon Feb 17 21:59:22 1986 Date-Received: Wed, 19-Feb-86 20:15:31 EST References: <245@aero.ARPA> Organization: Tektronix, Inc., Beaverton, OR Lines: 42 Keywords: string search Xref: linus net.unix:6577 net.unix-wizards:14004 net.wanted:7522 Summary: worry about output redirection use /dev/null to get filenames from grep In article <245@aero.ARPA>, sutton@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