ByteNoise

Unix tips

File manipulation

How to use grep recursively

find . -print0 | xargs -0 grep 'foo'

How to delete files over a week old, in the present directory and all its subdirectories

find . -type f -mtime +7 -daystart -print0 | xargs -0 rm -f

How to delete all hidden files (such as OS X's .DS_Store files), in the present directory and all its subdirectories

find . -type f -name '.*' -print0 | xargs -0 rm

A script to backup a website (files and a database), including the date of backup. Replace "foo" with the project name and "bar" with your MySQL password.

#!/bin/sh
date=`date "+%Y-%m-%d-%H-%M"`
mysqldump -uadmin -pbar foo > /home/zblade/foo-$date.sql
tar cfz /home/zblade/foo-$date.tgz /var/www/vhosts/foo.com/httpdocs
gzip —best /home/zblade/*.sql

These are simply tricks I've learnt during my years as a web developer. They may not be the best solutions. Please e-mail me any bugfixes or improvements to these examples. Thank you.