Skip to content

Instantly share code, notes, and snippets.

@koma5
Created March 23, 2011 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koma5/884126 to your computer and use it in GitHub Desktop.
Save koma5/884126 to your computer and use it in GitHub Desktop.
removes oldest file in a given folder, if the filesystem only has 10 Gigs remaining.
#!/bin/sh
dir=$1
minGigs=$2
available=`df --sync $dir | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{print $4}'`
#10 Gbytes in Kbytes
min=$(($minGigs*1024*1024))
if [ $min -gt $available ]
then
file2rm=`ls --sort=time $dir | awk '{ fname=$1 } END { print fname }'`
rm -rf $file2rm
echo "$file2rm removed"
else
echo "there's more than $minGigs Gigs"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment