Disk usage to show only select partitions?

0

I'd like to be able to only show disk usage for specific partitions in GB and a % after. Basically ignore swap, tmpfs, etc..

I'd also like to sum the disk usage amount and subtract from the total to get free space.

Right now I have something like this, but not sure how to use awk and select the partitions I want to count.

df -h | awk '$5 ~ /\%$/ print $1 " " $5}'

This is for a debian system.

Edit:

So figured out I can use / to limit the results, however, this only shows me how much is free.

df -h / | awk '{ a = $4 } END { print a }'

debianusr

Posted 2016-07-03T21:06:12.413

Reputation: 21

Why not simply grep? – gronostaj – 2016-07-03T21:12:13.917

Not familiar with the command – debianusr – 2016-07-03T21:18:23.747

"I'd also like to sum the disk usage amount and subtract from the total to get free space.". How is that different from what df -h already provides in the Avail column? – John1024 – 2016-07-03T21:48:56.447

df should accept a mountpoint as an argument. It may even be a directory or a file below the mountpoint. The tool will then display information for the appropriate mountpoint only. Try it: df -h /tmp or df -h /dev/urandom. You can specify multiple arguments in that fashion. – Kamil Maciorowski – 2016-07-03T22:04:54.040

You know there's df -x tmpfs, right? – user1686 – 2016-07-04T06:15:46.233

Answers

1

I am not sure what you are trying to do with awk, but you are complicating the expression needlessly. All you need to output the file system, free space and percentage occupancy is:

df -h /|awk '{ print $1, $4, $5 }'

However, this will not align the headers with the data. To preserve the alignment, use something like:

df -h /|awk '{ printf "%-60s %6s %6s\n", $1, $4, $5 }'

Here I have used a wide first field because my system disc is listed by UUID. To show percentage free space instead of occupancy, you can use:

df -h /|awk '{ printf $5=="Use%"?"%-60s %6s   Free%%\n":"%-60s %6s %6s%%\n", $1, $4, 100-$5 }'

In this case the % sign is ignored in the arithmetic expression. I don't know df rounds the percentage to the nearest integer, as I have assumed. If it rounds down, then 100-$5 will be rounded up, so instead use 99-$5 to get the free space rounded down.

AFH

Posted 2016-07-03T21:06:12.413

Reputation: 15 470

0

The question doesn't show exactly what the desired output is but this seems to match what you want:

df -h | grep -E --color=never 'Filesystem|/dev/'

The string Filesystem is included so that the output shows the human-friendly column headers. The /dev/ string is included because it eliminates the udev and tmpfs systems.

John1024

Posted 2016-07-03T21:06:12.413

Reputation: 13 893