Add an extra line to a number of files

echo "LINE TO ADD"  | tee -a FILE*

Run a command recursivly on an entire directory

find . -type f -print0 | xargs -0 dos2unix

Simple for loop

This is useful if you want to run the same command on a list of IP addresses Here we have a file called ip-list

And here we have the script that will loop through the list if IP addresses and perform a specific command

machines=`cat $machine`
echo Starting
for line in ${machines}; do
    echo ${line}
    scp -i privatekey file root@${line}:/folder/you/want/

Backing up and restoring PGSQL

Backup to tar file

pg_dump -F t ${dbname} > /data/backups/DBdump-${dbname}.tar

And restore

Create new DB

postgres=> create database marktest;
postgres=> grant all privileges on database marktest to postgres;

And the restore command

pg_restore -c -i -h -U postgres -d test -v "DBdump-${dbname}.tar" -W

Renaming all files in a folder

for f in *; do mv "$f" "${f/Huge/Monstrous}"; done