iA


Handy Unix commandlines

by jcf. Average Reading Time: less than a minute.

It’s hard to memorize all the fun things you can do with the shell on a *nix system.

Here’s my crib-sheet: Find all files containing string in the current directory tree

find . -type f -exec grep string {} \; -print

In all files in directories dir1 and dir2, replace “aaa” with “bbb”

#!/bin/sh

for i in `find ./dir1 ./dir2 -type f`; do
    sed -e"s/aaa/bbb/g" $i> $i.$$
    mv $i.$$ $i
done

tbc

2 comments on ‘Handy Unix commandlines’

  1. grep -r string *

    …”sed ARGS && mv ARGS” will be a little safer ;-)
    (reads “if sed ARGS; then mv ARGS; fi”)

    Regards,
    /k

  2. re: grep -r ….

    I’m on a Solarix box. No grep -r there.

    thanks for the tip about the return code – makes sense

Leave a Reply