Created
May 18, 2018 12:09
-
-
Save 0xBADC0FFEE/800304dae1eb8c3cc27c00e9e907a662 to your computer and use it in GitHub Desktop.
Bash script that remove oldest files recursively from a directory if free size is over a threshold
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 | |
DIRECTORY="/path/to/your/directory" | |
CAPACITY=95 | |
while [[ $(df $DIRECTORY | awk 'NR==2 && gsub("%","") {print$5}') -ge $CAPACITY ]];do | |
rm -rf $(find $DIRECTORY -mindepth 1 -printf '%T+ %p\n' | sort | awk 'NR==1 {print$2}') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment