Skip to content

Instantly share code, notes, and snippets.

@mhaimes
Created June 19, 2023 19:38
Show Gist options
  • Save mhaimes/e450f9884d013547860aac3a6aedbe9a to your computer and use it in GitHub Desktop.
Save mhaimes/e450f9884d013547860aac3a6aedbe9a to your computer and use it in GitHub Desktop.
check for how many bytes are left on a device where a particular folder exists
#!/usr/bin/env bash
## Usage: ./available_bytes.sh # checks device where current directory exists
## ./available_bytes.sh /boot # checks device where /boot exists
if [ $# -lt 1 ]; then
TARGET=$PWD
else
TARGET=$1
fi
DF_ENTRIES=$(df $TARGET | tail -n 1)
for entry in $DF_ENTRIES; do
[[ $entry =~ "%" ]] && break;
AVAILABLE=$entry
done
echo $AVAILABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment