On Tue, 22 Apr 1997, Kevin J Poorman wrote: > hello > > As a somewhat unix/Linux newbie I have a few questions for this list: > > they are in no spesific order: > > 1: I have a text file that in of itself is a list of files. I would > like to take that list and grep though them to find a string. I think > this can be done with a shell script (Bash) but I have know idea how. > Can anyone give me some pointers and or post a script ? ... TIA
grep "search_regexp" `cat filelist.txt` The ` (not ' and not ") tells bash to evaluate the enclosed command. if "filelist.txt" is very large, then use: xargs grep "search_regexp" <filelist.txt > 2: The purpose of the above question is to find a file that has a > string (IE search all the files on the hard drive for the string "foo" > and list the files that have foo in it) Now that I know what file > has "foo" in it I need to log all the programs that write to this > file ? eg. program foobar and program foobarx both write to text file > /usr/lib/cows I need to know what program is writing to that file and > when find / | xargs grep "/usr/lib/cows" The xargs method is used here because the find is likely to generate thousands of lines of output which would exceed bash's input line buffer. this will search every file on the system, which will be very slow. if you know that you are looking only for, e.g., C source code files (*.c) then you can do: find / -name "*.c" | xargs grep "/usr/lib/cows" see 'man find' for more details. find is very very versatile. It can find files based on mod time, access time, permissions, ownership, and more. You can speed the whole job up a lot if you use locate rather than find: locate / | xargs grep "/usr/lib/cows" or locate / | grep "\*\.c" | xargs grep "/usr/lib/cows" locate is a *lot* kinder to your system - it searches a database of files on your system (generated once/day by updatedb) rather than searching the actual disk. The drawback with locate is that a) it only lists files which were on the system the last time updatedb was run, and b) it only lists files which are visible to user 'nobody' (unless you edit the /etc/cron.daily/find script so that it runs as root rather than nobody. also, locate can only do searches based on filename. The locate database only stores filename and no other information. If you do hack the /etc/cron.daily/find script, and you have more than one person who uses the system then i'd suggest modifying the script so that it generates TWO db files - the original one, and another one for root. craig -- craig sanders networking consultant Available for casual or contract temporary autonomous zone system administration tasks. -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .