How to print only disk usage percentage of linux similar to memory percentage.
for memory percentage i’m using this command:
free -m | awk 'NR==2{printf "%.2ft", $3*100/$2 }'
output:
12.17
like this is there any command for knowing disk usage percentage ?
Advertisement
Answer
Use df
:
$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 1936588 0 1936588 0% /dev tmpfs 1957840 7496 1950344 1% /dev/shm tmpfs 783140 1864 781276 1% /run /dev/sda6 518603776 12601324 504532516 3% / tmpfs 1957844 27848 1929996 2% /tmp /dev/sda6 518603776 12601324 504532516 3% /home /dev/sda5 999320 289900 640608 32% /boot tmpfs 391568 1696 389872 1% /run/user/1000 /dev/sdb1 1953512032 1952705324 806708 100% /run/media/mhawke/Seagate Expansion Drive
For one mount point:
$ df /boot Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda5 999320 289900 640608 32% /boot
Percent usage:
$ df --output=pcent /boot Use% 32%
Excluding header:
$ df --output=pcent /boot | grep -v Use 32% $ usage=$(df --output=pcent /boot | grep -v Use) $ echo $usage 32