Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!lll-crg!gymble!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix Subject: Re: Need unix command file HELP! Message-ID: <2981@umcp-cs.UUCP> Date: Sat, 1-Feb-86 10:51:25 EST Article-I.D.: umcp-cs.2981 Posted: Sat Feb 1 10:51:25 1986 Date-Received: Mon, 3-Feb-86 04:41:05 EST References: <245@aero.ARPA> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 42 Keywords: Unix, string search, Sake o nomimasu ka? In article <245@aero.ARPA> sutton@aero.UUCP (Stew Sutton) writes: > We are looking for a utility that can, when given a arbitrary string, > locate all occurences of that string anywhere on the system. First: Since you want to check all files on the machine, you should immediately think `find'---likewise for `all files within particular directory trees', which is of course the general case. Second: Since you want to match strings within the files, you should immediately think `grep' (or variants). > The utility [should] return all the files (and their pathnames > from the root) to the screen. If you want matching lines printed, that is easy; if you want the entire contents of the file printed, that is also easy. But I will assume that the names alone are sufficient. > Of course if the protections on the file indicate that the file > cannot be read, the program should ignore that file and keep > on going. Also easy: just discard error messages from grep. So, thinking `find' and `grep' (but I will use egrep since it is usually faster), you consult the man entries, and . . . : $ find / -exec egrep "pattern" {} \; -print 2> /dev/null This is a bit more difficult in the C shell, as it is unable to redirect stderr without also redirecting stdout. However, if you already know where stdout is going, it can be done: % (find / -exec egrep "pattern" {} \; -print > /dev/tty) >& /dev/null (My own solution to the C shell's redirection quirks is to run `sh' before doing anything complex.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu