marshall@arcaner:~$ cat ./cleanup_builds.sh #!/bin/bash #Created by Ben Fisher # #2007-Oct-20 # #Delete all but the five most recent directories in a path, for warlock2 builds. # #Pull directories, stat for mtime, sort numerically, and store (overwrite, not append, each time). # find /home/web/arcaner.com/warlock2-builds -maxdepth 1 -type d -print0 | xargs -0 -i stat -c "%y %n" {} | sort -nr > ~/.w2bldclean_check # #Number of directories total. # lines=`cat ~/.w2bldclean_check | wc -l` # #Number of directories minus 5 (from the correctly time-sorted list). # rmlines=$(($lines - 5)) # #Sorted numerically in reverse, so tail by a value equal to 5 less than the total in the list, and then remove those. # cat ~/.w2bldclean_check | tail -`echo $rmlines` | cut -d ' ' -f 4 | xargs -i rm -Rf {} # #If less than 5, this does nothing.