Bash - Get available size / free space

By xngo on June 30, 2019

The Bash function below will return the number of kilobytes of free space of the provided path.

function GET_FREE_SPACE_KB()
{
  local LOCATION=$1
  local FREE_SPACE_MB=$(df -k --output=avail ${LOCATION} | tail -1 )
  echo ${FREE_SPACE_MB}
}

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.