Replace on the command line

# sample replace linux command line. (command comes with mysql installation)
# ie replace a b -- filelist
# -v = verbose
# a, b = strings from,to can be quoted. if double, escape things like $ with a backslash

replace -v "string to replace; \$a = \$b " 'string to insert; $c = $d ' -- *


# to create a compressed tar acrchive

tar -cvzf foo.tar.gz *.cc *.h

# To untar/unzip

tar -xvzf filename

x = ie reverse: untar instead of tar
v = verbose
z = handle compression
f = followed by filename


 To grep recursively thru all subfolders etc

grep -r 'search stuff' *

-r = recursive

if a wild isn't used as filepattern, then it appears to fail to act recursively


To grep very widely try:

locate exim | xargs grep -in 'blackhole'

ie find all files with 'exim' in their path and grep for blackhole within them!
best to check how many lines first! (ie do a locate first then the whole lot!


Or to search within a particular folder (and it's sub folders)

find -iname '*exim*' | xargs grep -in 'blackhole'

Setting up certificates for SSH, RSYNC and SCP

On master box: (ie the computer that originates an rsync command)

cd ~ 
ssh-keygen -t rsa

don't use a passphrase , so hit enter and accept defaults

this will create files in the .ssh directory:

  • id_rsa

Send the public key to the slave box using scp:

cd .ssh


On the slave box, logged in as someuser

cd ~/.ssh
touch authorized_keys # creates files miss this step if already exists!
chmod 600 authorized_keys
cat ../ >>authorized_keys
rm ../

On master box test with

ssh -2 -v

[updated Jan 2017 to use rsa instead of dsa keys. Dsa now deprecated.]

Check the first line of each CGI script

When updating my php handing for cgi I needed to confirm the first line was changed from





So how to view all the first lines without lots of work?


(starting from the document root for the site)


1. Create a list of all cgi files

find ./  -name '*.cgi' >cgilist.txt

2. Use head to display the first 18 characters of each file

xargs --arg-file=cgilist.txt head -c 18

I opt to display the first 18 characters instead of the first line to avoid problems with binary files.

On-line Code Manual