One the problems I’ve suffered is soooo much disk space wasted on log files, but how do you delete files older than say 5 days from a number of different users?

find /home -type d -exec ls -d {} \; | grep logfiles | grep -v logfiles$ | awk ‘{print “find “$1″/* -mtime +5 | xargs rm “}’ > cleanup.sh

The command above will create you a shell script call cleanup.sh all you have to do is run it (. cleanup.sh)

It looks fun, but if we breakdown the commands, it really is quite easy.

find /home -type d -exec ls -d {} \; basically just searched for all directories starting from /home

grep logfiles | grep -v $logfiles search the results for logfiles in the name, but not $logfiles

awk ‘{print “find “$1″/* -mtime +5 | xargs rm “}’ is what creates the shell script, find $1 (one of the directories) -mtime +5 (older that 5 days) xarmgs rm (print rm followed by the directory found before)