-
-
Save DartPower/1ba0d17c87bc7fdd069702a15c48f7dc to your computer and use it in GitHub Desktop.
Remove oldest .tgz files, if free space less than 50GB
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
#!/usr/bin/env bash | |
# set -o nounset | |
set -o errexit | |
shopt -s dotglob | |
# Remove oldest .tgz files, if free space less than 50GB | |
# | |
# License: CC0 1.0 or newer | |
# https://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# You can download this script here: https://gist.github.com/vazhnov/177fa8dfb474ed108860731dca21c591 | |
dir="/tmp" | |
while [ $(df --output=avail ${dir} | tail -n 1) -lt 50000000 ]; do | |
# See for details: http://mywiki.wooledge.org/BashFAQ/003 | |
unset -v oldest | |
for file in "$dir"/*tgz; do | |
[[ -z $oldest || $file -ot $oldest ]] && oldest=$file | |
done | |
rm -f "${oldest}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment