[NTLUG:Discuss] total drive size
MadHat
madhat at unspecific.com
Wed Mar 12 14:05:30 CST 2003
On Wed, 2003-03-12 at 13:45, Fred James wrote:
> >
> >better yet, just use awk (wasn't thinking before)
> >df -k | grep "^/dev" | awk '{print Total+=$3 }' | tail -1 | awk '{print
> >$1/1024, "Mb used"}'
> >
> >which works with SSH
> >$ ssh dodo df -k | grep "^/dev" | awk '{print Total+=$3 }' | tail -1 |
> >awk '{print $1/1024, "Mb used"}'
> >4638.88 Mb used
> >
> >want to know free?
> >$ ssh dodo df -k | grep "^/dev" | awk '{print Total+=$4 }' | tail -1 |
> >awk '{print $1/1024, "Mb free"}'
> >12722.4 Mb free
> >
> >
> >
> >
> >
> And if his orginal question was for the total of all space;
>
> $ ssh dodo df -k | grep "^/dev" | awk '{print Total+=$2 }' | tail -1 |
> awk '{print $1/1024, "Mb free"}'
>
> will obviously do it.
Right, the $2 is total space, $3 is used space and $4 is free space,
because of the order df outputs the entries.
Line by line
df -k | \ # gets the total disk usage info
grep "^/dev" | \ # grabs only the lines that are real devices
awk '{print Total+=$2 }' |\ # keeps the running total and prints it
tail -1 |\ # grabs the last line (the real total)
awk '{print $1/1024, "Mb"}' # converts it into Mb for easier reading
BTW, this also works on FreeBSD and Solaris
--
MadHat at Unspecific.com
`But I don't want to go among mad people,' Alice remarked.
`Oh, you can't help that,' said the Cat: `we're all mad here...'
-- Lewis Carroll - _Alice's_Adventures_in_Wonderland_
More information about the Discuss
mailing list