How to sort df -h out put :

Hello every one ,

      I am just trying to sort df -h out in a particular order  to differentiate SAN disks and local disks .. does any body have any script or any useful command ?? 

thanks in advance ..

 df -h | sort

is a starting point.

Please show us what df -h gives for input to sort and your expected output.
Device and other things are not really universal in Solaris, so I'm not clear what your problem is. Normally the output of df is pretty much usable as is.

1 Like

Thanks Jim for ur time and for ur response ... here is my df -h out put

mdsuaor18:> df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/md/dsk/d1         4.9G   3.4G   1.5G    70%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                    52G   1.1M    52G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap2.so.1
                       4.9G   3.4G   1.5G    70%    /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap2.so.1
                       4.9G   3.4G   1.5G    70%    /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
fd                       0K     0K     0K     0%    /dev/fd
/dev/md/dsk/d4         2.0G   1.1G   871M    56%    /var
swap                    52G   5.6M    52G     1%    /tmp
swap                    52G    32K    52G     1%    /var/run
/dev/md/dsk/d170        39G    18G    21G    45%    /d02
/dev/md/dsk/d180       315G   175G   139G    56%    /d01
/dev/md/dsk/d5         2.0G   415M   1.5G    22%    /opt
/dev/md/dsk/d160        99G   3.5G    95G     4%    /archive
/dev/md/dsk/d190       606G   330G   271G    55%    /d03
/dev/md/dsk/d100        93M    70M    14M    84%    /home
/dev/md/dsk/d150        98G    12G    85G    13%    /orabackup
mdsuaor18:>

i am trying to sort this out put based on mount points in the following order

/d01 
/d02
/d03
/archive 
/orabackup 

any suggestions ? ty ...

Hi new2uniks,

What kind of sort is that?

Shouldn't be /archive ordered before than /d01? I can't see the point.

Try the following;

df -h | grep -v Mounted | sort -k 6,6 

Based on the assumption that you actually do want sorted output:)

1 Like

i am little :confused: by ur qn .. i dnt mind about /archive and /orabackup order ... they may come first or last .. but the rest should be in order like d01 d02 d03 ...

Sorry about that should have included a separator in the command as follows;

df -h | grep -v Mounted | sort -t"        " -k 6,6

After the first set of quote marks you need to hold down the ctrl key and press lowercase v and then uppercase I before closing the quotes this will give you a tab separator in the command. I don't have access to my Sun box just now so cant test - sorry.

Regards

Dave

1 Like
clove:> df -h | grep -v Mounted | sort -t"      "-k 6,6
sort: can't stat 6,6: No such file or directory

when I am trying to test that out its giving me this error .. I did like you said but still not able to run the command ...

---------- Post updated at 07:18 PM ---------- Previous update was at 07:16 PM ----------

clove:> df -h | grep -v Mounted | sort -t"      "-k 6,6
sort: can't stat 6,6: No such file or directory

I tested on one my servers ... its giving me the error ... i did like you said after quotes holding down ctl key and pressing v , I ... but still nt able to run the command ..

---------- Post updated at 07:25 PM ---------- Previous update was at 07:18 PM ----------

never mind its working .. thanks a lot ...

Glad you got it working new2uniks, sorry I wasn't more help.

Regards

Dave