Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Supp0rtLinux

macrumors member
Original poster
Feb 28, 2008
92
27
I used Geektool extensively and one of my scripts does a "df -h", but excludes a few local volumes so it only shows the main HD and any mounted USB/firewire volumes. I just rolled up to the ML GM and I now when running a "df" I now see columns for "iused", "ifree" and "%iused". You used to have to specify the -i flag to see this. According to the man page, this is now default and the result is that the extra columns are skewing my Geektool layout. I want to exclude them. I know I can do so with awk or cut. However, doing so with either drops the formatting. Example:

stimpy:~ adavis$ df -h|grep -v devfs|grep -v "map"|grep -v "localhost"|grep -v "Boot OS X"|grep -v "Recovery HD"
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1 476Gi 195Gi 280Gi 42% 51312849 73422228 41% /
/dev/disk3s2 186Gi 8.8Mi 186Gi 1% 0 0 100% /Volumes/SHARED
/dev/disk3s1 410Gi 211Gi 199Gi 52% 55367029 52087612 52% /Volumes/PortableHFS
/dev/disk5 465Gi 134Gi 331Gi 29% 35208278 86726563 29% /Volumes/Time Machine (Work)
/dev/disk6s2 400Gi 201Gi 199Gi 51% 52687032 52086588 50% /Volumes/Documents (Encrypted)


stimpy:~ adavis$ df -h|grep -v devfs|grep -v "map"|grep -v "localhost"|grep -v "Boot OS X"|grep -v "Recovery HD"|awk '{print $1, $2, $3, $4, $5, $9}'
Filesystem Size Used Avail Capacity Mounted
/dev/disk1 476Gi 195Gi 280Gi 42% /
/dev/disk3s2 186Gi 8.8Mi 186Gi 1% /Volumes/SHARED
/dev/disk3s1 410Gi 211Gi 199Gi 52% /Volumes/PortableHFS
/dev/disk5 465Gi 134Gi 331Gi 29% /Volumes/Time
/dev/disk6s2 400Gi 201Gi 199Gi 51% /Volumes/Documents


… and using cut has similar results...

Anyone have any clues as to how to strip the inode info off the output of "df" without dropping the formatting of df? I want the output and formatting and all columns except the three "i" columns of inode info.
 

TorranceTM

macrumors newbie
Jul 27, 2012
1
0
I just ran into the same issue last night after installing ML, but I am not using GeekTool for the output display - Just in an overnight script.

I fixed the DF issue by using the below Bash Script, this will output the DF output to a file in your home directory called CutDF.txt which you could monitor this file in GeekTool. Just setup the script to run from CRON on a timed interval.

-------- Script Start

#!/bin/sh

TmpDF=$(mktemp /tmp/$(basename $0).$$.XXXXXX) || exit 1
DisplayCutDF=$HOME"/CutDF.txt"

/bin/df -h | grep -e ^Filesystem > "$TmpDF"
IFSOLD=$IFS
IFS=$'\n'
HRDFHold=($(<"$TmpDF"))
IFS=$IFSOLD

for (( a=0; a<${#HRDFHold[@]}; a++)); do
HRDFLine=${HRDFHold[$a]:0:43}${HRDFHold[$a]:69:($((${#HRDFHold[$a]}-69)))}
echo "$HRDFLine" > $DisplayCutDF
done
unset HRDFHold

/bin/df -h | grep -e ^/dev/ | sort -k 9 > "$TmpDF"

IFSOLD=$IFS
IFS=$'\n'
HRDFHold=($(<"$TmpDF"))
IFS=$IFSOLD

for (( a=0; a<${#HRDFHold[@]}; a++)); do
HRDFLine=${HRDFHold[$a]:0:42}${HRDFHold[$a]:68:($((${#HRDFHold[$a]}-68)))}
echo "$HRDFLine" >> $DisplayCutDF
done
unset HRDFHold
rm "$TmpDF"

--------- Script End

Attached is the script in TXT file, change extension to .sh and a sample output.

Hope this helps,

Tom.
 

Attachments

  • OldDFOutput.txt
    672 bytes · Views: 110
  • CutDF.txt
    501 bytes · Views: 140

MrElvey

macrumors member
Feb 22, 2010
34
6
Umm... take another look at the output of 'man df'!

For your convenience, I draw your attention to the bolded bit of a line from the man page:

-i Include statistics on the number of free inodes. This option is now the default to conform to Version 3 of the Single UNIX Specification (``SUSv3'') Use -P to suppress this output.
:D


BTW, I have this in my .bashrc; I find I never care about /dev, /net or /home.

df () { /bin/df -Pk $* | grep "Filesystem\|disk\|Volumes"; /bin/df -Phn $* | grep "Filesystem\|disk\|Volumes"; }

(Come to think of it, perhaps grep --v "dev\|net\|home" would be safer...)
 

Supp0rtLinux

macrumors member
Original poster
Feb 28, 2008
92
27
I did look at 'man df'. The problem is that when you use the -P option, you lose the friendly rounding to the nearest Mb, Gb, Tb, etc and are shown everything in blocks. The goal is to see the df output with the benefits of "-h", but not see the inode info by using "-P". The two don't seem to work together for the desired result. See below:

gentoo:~ god$ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1 476Gi 227Gi 248Gi 48% 59638355 65096722 48% /
devfs 198Ki 198Ki 0Bi 100% 685 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
localhost:/xxx 476Gi 476Gi 0Bi 100% 0 0 100% /Volumes/MobileBackups
/dev/disk2s1 410Gi 221Gi 189Gi 54% 57942099 49512542 54% /Volumes/PortableHFS
/dev/disk2s2 186Gi 27Gi 159Gi 15% 0 0 100% /Volumes/SHARED
/dev/disk4 465Gi 128Gi 337Gi 28% 33669157 88261588 28% /Volumes/Time Machine (Work)
/dev/disk5s2 400Gi 211Gi 189Gi 53% 55262102 49511518 53% /Volumes/Documents (Encrypted)
/dev/disk3s3 128Mi 12Mi 116Mi 10% 3075 29691 9% /Volumes/Boot OS X

gentoo:~ god$ df -h -P
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk1 997880632 476594752 520773880 48% /
devfs 395 395 0 100% /dev
map -hosts 0 0 0 100% /net
map auto_home 0 0 0 100% /home
localhost:/xxx 997880632 997880632 0 100% /Volumes/MobileBackups
/dev/disk2s1 859637144 463536808 396100336 54% /Volumes/PortableHFS
/dev/disk2s2 390531008 56718208 333812800 15% /Volumes/SHARED
/dev/disk4 975445976 269353272 706092704 28% /Volumes/Time Machine (Work)
/dev/disk5s2 838188976 442096832 396092144 53% /Volumes/Documents (Encrypted)
/dev/disk3s3 262144 24616 237528 10% /Volumes/Boot OS X

So perhaps instead of telling us to look at "man df" and pointing out the -P option that you ASSumed we missed, instead you should actually run the command yourself and realize you're just wasting bits with your typing.
 

zurichuk

macrumors regular
Feb 23, 2011
122
0
I probably don't deserve to be in this technical thread, but I played around.

Does df -Ph work as opposed to df -h -P?
 

Supp0rtLinux

macrumors member
Original poster
Feb 28, 2008
92
27
Works for me as well. So does "df -P -h". Thanks much. Who knew that switching the order would make the difference. :)
 

Mal

macrumors 603
Jan 6, 2002
6,253
30
Orlando
Works for me as well. So does "df -P -h". Thanks much. Who knew that switching the order would make the difference. :)

I'm guessing it sets the flags as it gets to them, overriding any previous ones that are conflicting. So if you set the -h flag first, the -P overrides it with it's default options. When you do it the other way around, -h only overrides the conflicting parts of the -P command, so you get what you're looking for from both.

jW
 

MrElvey

macrumors member
Feb 22, 2010
34
6
I did look at 'man df'. The problem is that when you use the -P option, you lose the friendly rounding to the nearest Mb, Gb, Tb, etc and are shown everything in blocks. The goal is to see the df output with the benefits of "-h", but not see the inode info by using "-P". The two don't seem to work together for the desired result. See below:

gentoo:~ god$ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1 476Gi 227Gi 248Gi 48% 59638355 65096722 48% /
devfs 198Ki 198Ki 0Bi 100% 685 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
localhost:/xxx 476Gi 476Gi 0Bi 100% 0 0 100% /Volumes/MobileBackups
/dev/disk2s1 410Gi 221Gi 189Gi 54% 57942099 49512542 54% /Volumes/PortableHFS
/dev/disk2s2 186Gi 27Gi 159Gi 15% 0 0 100% /Volumes/SHARED
/dev/disk4 465Gi 128Gi 337Gi 28% 33669157 88261588 28% /Volumes/Time Machine (Work)
/dev/disk5s2 400Gi 211Gi 189Gi 53% 55262102 49511518 53% /Volumes/Documents (Encrypted)
/dev/disk3s3 128Mi 12Mi 116Mi 10% 3075 29691 9% /Volumes/Boot OS X

gentoo:~ god$ df -h -P
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk1 997880632 476594752 520773880 48% /
devfs 395 395 0 100% /dev
map -hosts 0 0 0 100% /net
map auto_home 0 0 0 100% /home
localhost:/xxx 997880632 997880632 0 100% /Volumes/MobileBackups
/dev/disk2s1 859637144 463536808 396100336 54% /Volumes/PortableHFS
/dev/disk2s2 390531008 56718208 333812800 15% /Volumes/SHARED
/dev/disk4 975445976 269353272 706092704 28% /Volumes/Time Machine (Work)
/dev/disk5s2 838188976 442096832 396092144 53% /Volumes/Documents (Encrypted)
/dev/disk3s3 262144 24616 237528 10% /Volumes/Boot OS X

So perhaps instead of telling us to look at "man df" and pointing out the -P option that you ASSumed we missed, instead you should actually run the command yourself and realize you're just wasting bits with your typing.

It seems Supp0rtLinux didn't see the import of this part of my previous post " /bin/df -Phn "

Supp0rtLinux ASSumed I didn't use the command I obviously use use so often I've written a shell function to make it work better.

I believe Supp0rtLinux saw the documentation of the -P option and chose not to mention it.;) Others wouldn't be so charitable. :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.