Created
March 23, 2011 22:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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