Skip to content

Instantly share code, notes, and snippets.

@TheFlash2k
Created June 22, 2023 16:13
Show Gist options
  • Save TheFlash2k/4fa3762cd2c952df214c8d1c7541b155 to your computer and use it in GitHub Desktop.
Save TheFlash2k/4fa3762cd2c952df214c8d1c7541b155 to your computer and use it in GitHub Desktop.
A simple bash utility to finding the free space. (idk tbh)
#!/bin/bash
# Finding the base drive
drive_name=`df -h | rev | grep -E '^/\s' | rev | cut -d ' ' -f 1 | rev | cut -d '/' -f 1 | rev`
if [[ $# == 1 ]]; then
drive_name=$1
fi
res=`df -h | grep $drive_name`
if [[ $? != 0 ]]; then
echo "[!] $drive_name is an invalid drive!"
exit 1
fi
total=`echo $res | cut -d ' ' -f 2`
used=`echo $res | cut -d ' ' -f 3`
free=`echo $res | cut -d ' ' -f 4`
percent=`echo $res | cut -d ' ' -f 5`
mount=`echo $res | cut -d ' ' -f 6`
echo "Drive : $drive_name"
echo "Total : $total"
echo "Used : $used ($percent)"
echo "Free : $free"
echo "Mount : $mount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment