Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script that remove oldest files recursively from a directory if free size is over a threshold
#!/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
You can’t perform that action at this time.