Last active
February 21, 2019 12:33
-
-
Save MatthewJohn/afc143dd40fe09a34d0e3d5f9584957b to your computer and use it in GitHub Desktop.
One-liner prune oldest file to reach disk percentage free
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/bash | |
export WANTED_PERC_FREE=92 DEL_DIR=./ MAX_DELETIONS=10; for i in $(find ${DEL_DIR} -type f -printf "%TY%Tj %p\n" | sort -n | gawk '{ print $2 }' | head --lines=$MAX_DELETIONS); do if (( $(df ${DEL_DIR} --output=pcent | tail -1 | sed 's/[^0-9]//g') > $WANTED_PERC_FREE )); then rm $i; else exit 1; fi; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One liner to delete all files in directory, from oldest to newest, in order to reach a given disk utilisation percentage, with a hard limit of deletions.