Wednesday, April 19, 2006

Useful Unix Commands

There are certain Unix commands that I always forget and have to re- look up, so I though I would start to compile them here for future reference!

(1) Find a string within any file (searches within the current directory and any sub-directories, recursively) [ref]...

csdalpha1a.sbu.ac.uk> find . -exec grep "pateld" '{}' \; -print

...which resulted in...

  <owner>pateld@lsbu.ac.uk</owner>
./cgi-bin/expirychecker/ExpiryData.xml
  <owner>pateld@lsbu.ac.uk</owner>
./cgi-bin/expirychecker/ExpiryDataLastWeek.xml

owner=pateld@lsbu.ac.uk
./progs/bit/msc/computing/ids.shtml
csdalpha1a.sbu.ac.uk>         

(2) UNTESTED! Find String1 within any file (searches within the current directory and any sub-directories, recursively) and replace it by String2 [ref]...

find ./ -type f -exec sed -i 's/string1/string2/' {} \;