Professional Web Applications Themes

Getting free and used space for a filesystem in a generic Unix flavor - Linux / Unix Administration

Hi! I usually use these following commands to get the total, used and free space, in Kbytes, for a filesystem. This works fine for HP-UX: [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ uname -a HP-UX backup2 B.11.00 U 9000/800 670359373 unlimited-user license [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . Filesystem 1024-blocks Used Available Capacity Mounted on /dev/vg00/lvol3 142075 60985 81090 43% / Total space [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . | tail -1 | tr -s '[:space:]' | cut -d " " -f 2 142075 Used space [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . | tail -1 | tr -s '[:space:]' | cut -d " " ...

  1. #1

    Default Getting free and used space for a filesystem in a generic Unix flavor

    Hi!

    I usually use these following commands to get the total, used and free
    space, in Kbytes, for a filesystem. This works fine for HP-UX:

    [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ uname -a
    HP-UX backup2 B.11.00 U 9000/800 670359373 unlimited-user license

    [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP .
    Filesystem 1024-blocks Used Available Capacity Mounted on
    /dev/vg00/lvol3 142075 60985 81090 43% /

    Total space
    [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . | tail -1 | tr
    -s '[:space:]' | cut -d " " -f 2
    142075

    Used space
    [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . | tail -1 | tr
    -s '[:space:]' | cut -d " " -f 3
    60985

    Free space
    [oraclebackup2 P01OL1 /EMC2/BCV/oracle/bin]$ df -kP . | tail -1 | tr
    -s '[:space:]' | cut -d " " -f 4
    81090



    But the df command has different outputs and parameters for different
    Unix flavors. In a Sun Solaris I got:

    [oracle P00FR1 /tools/oracle]$ uname -a
    SunOS tafraud 5.9 Generic_117171-12 sun4u sparc SUNW,Sun-Fire

    [oracle P00FR1 /tools/oracle]$ df -kP .
    df: unknown option: P
    Usage: df [-F FSType] [-abeghklntVv] [-o FSType-specific_options]
    [directory | block_device | resource]


    Does anyone has a way to get total and free space (used can be computed
    using the two previous) for a filesystem in any Unix flavor?

    Best regards,
    Luis Santos

    lcdsantos@gmail.com Guest

  2. #2

    Default Re: Getting free and used space for a filesystem in a generic Unix flavor

    On 2006-01-13, com wrote: 

    When popsting code via Google groups, please use lines short
    enough that Google's broken interface doesn't mangle them. It is
    often hard to determine exactly what is meant when the lines are
    borken at seemingly arbitrary points.
     

    df | {
    read ## discard headers
    while read par blocks used avail percent mount
    do
    [ -z "$blocks" ] && read blocks used avail percent mount

    ## Now you have all the information for the mountpoint
    ## in 6 variables; use them as you wish, e.g.:
    printf "Total: %12d Used: %12d Free: %12d %s\n" \
    "$(( $blocks * 1024 ))" \
    "$(( $used * 1024 ))" \
    "$(( $avail * 1024 ))" \
    "$mount"
    done
    }


    --
    Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence
    Chris Guest

  3. #3

    Default Re: Getting free and used space for a filesystem in a generic Unix flavor

    In article <googlegroups.com>,
    com wrote: 

    The 'df -kP' output is almost exactly the same as 'bdf' (the header is slightly
    different), which is the standard tool on HP-UX. On most other platforms, 'df
    -k' is equivalent output.

    Kevin

    --
    Unix Guy Consulting, LLC
    Unix and Linux Automation, Shell, Perl and CGI scripting
    http://www.unix-guy.com
    Kevin Guest

Similar Threads

  1. What Linux flavor to use
    By xsxtreme in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: December 7th, 11:56 AM
  2. Free web space
    By phpziobudda@libero.it in forum PHP Development
    Replies: 3
    Last Post: October 10th, 06:38 AM
  3. how to get (free) space of a drive?
    By Alexander Riegel in forum PHP Development
    Replies: 0
    Last Post: July 13th, 03:12 PM
  4. How much free space left on ext. FW drive?
    By Simon Slavin in forum Mac Applications & Software
    Replies: 1
    Last Post: June 25th, 10:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139