Vishnu Vishnu - 10 months ago 75
Linux Question

Find usage % of a directory in the disk

How to find the % of disk space used by a directory using du command in linux.

Answer Source

You need to use a combination of df (file system) and du (file space usage). Just one of these commands won't do.

#!/usr/bin/env bash
totalSize=$(du -s -k $mydir | cut -f1)
fileSystemSize=$(df --output=size $mydir | tail -1)
pct=$(echo "scale=2;($totalSize/$fileSystemSize)*100" | bc -l )
echo "$mydir is $pct"%""

Is this what you are looking for?

/home/user/Downloads is 12.00%