linux disc space

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DataSmash

    #1

    linux disc space

    I simply want to capture the free disc space in a variable so that I
    can compare changes. I'm aware of a few commands like "df -h" or "du -
    k", but I can't figure out how to capture those values as a variable.
    I also looked at os.statvfs(), but that output doesn't seem to make
    any sense at all to me, knowing the size of the disc.
    Thanks for your help!
    R.D.
  • Chris

    #2
    Re: linux disc space

    On Feb 15, 7:10 pm, DataSmash <r...@new.rr.co mwrote:
    I simply want to capture the free disc space in a variable so that I
    can compare changes. I'm aware of a few commands like "df -h" or "du -
    k", but I can't figure out how to capture those values as a variable.
    I also looked at os.statvfs(), but that output doesn't seem to make
    any sense at all to me, knowing the size of the disc.
    Thanks for your help!
    R.D.
    import os, statvfs
    s = os.statvfs(".")
    freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAI L]

    HTH,
    Chris

    Comment

    • Jeff Schwab

      #3
      Re: linux disc space

      Chris wrote:
      On Feb 15, 7:10 pm, DataSmash <r...@new.rr.co mwrote:
      >I simply want to capture the free disc space in a variable so that I
      >can compare changes. I'm aware of a few commands like "df -h" or "du -
      >k", but I can't figure out how to capture those values as a variable.
      >I also looked at os.statvfs(), but that output doesn't seem to make
      >any sense at all to me, knowing the size of the disc.
      >Thanks for your help!
      >R.D.
      >
      import os, statvfs
      s = os.statvfs(".")
      freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAI L]
      Is it worth distinguishing free bytes from available bytes? I've never
      seen them differ, and I'm not sure how they ever would...

      import os
      import statvfs

      def free_bytes(path ):
      stats = os.statvfs(path )
      return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]

      def avail_bytes(pat h):
      stats = os.statvfs(path )
      return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAI L]

      if __name__ == '__main__':
      import sys
      for path in sys.argv[1:]:
      print "%s:" % path,
      print "%dK free," % (free_bytes(pat h) / 1024),
      print "%dK available" % (avail_bytes(pa th) / 1024)

      Comment

      • DataSmash

        #4
        Re: linux disc space

        On Feb 15, 1:32 pm, Jeff Schwab <j...@schwabcen ter.comwrote:
        Chris wrote:
        On Feb 15, 7:10 pm, DataSmash <r...@new.rr.co mwrote:
        I simply want to capture the free disc space in a variable so that I
        can compare changes. I'm aware of a few commands like "df -h" or "du -
        k", but I can't figure out how to capture those values as a variable.
        I also looked at os.statvfs(), but that output doesn't seem to make
        any sense at all to me, knowing the size of the disc.
        Thanks for your help!
        R.D.
        >
        import os, statvfs
        s = os.statvfs(".")
        freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAI L]
        >
        Is it worth distinguishing free bytes from available bytes? I've never
        seen them differ, and I'm not sure how they ever would...
        >
        import os
        import statvfs
        >
        def free_bytes(path ):
        stats = os.statvfs(path )
        return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]
        >
        def avail_bytes(pat h):
        stats = os.statvfs(path )
        return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAI L]
        >
        if __name__ == '__main__':
        import sys
        for path in sys.argv[1:]:
        print "%s:" % path,
        print "%dK free," % (free_bytes(pat h) / 1024),
        print "%dK available" % (avail_bytes(pa th) / 1024)

        Chris,
        Much thanks. That's just what I need.

        Jeff,
        Not sure what's taking up the "available" space, but it's about 12GB
        on my system.
        Interesting.

        Thanks.

        Comment

        • Jeff Schwab

          #5
          Re: linux disc space

          DataSmash wrote:
          On Feb 15, 1:32 pm, Jeff Schwab <j...@schwabcen ter.comwrote:
          >Chris wrote:
          >>On Feb 15, 7:10 pm, DataSmash <r...@new.rr.co mwrote:
          >>>I simply want to capture the free disc space in a variable so that I
          >>>can compare changes. I'm aware of a few commands like "df -h" or "du -
          >>>k", but I can't figure out how to capture those values as a variable.
          >>>I also looked at os.statvfs(), but that output doesn't seem to make
          >>>any sense at all to me, knowing the size of the disc.
          >>>Thanks for your help!
          >>>R.D.
          >>import os, statvfs
          >>s = os.statvfs(".")
          >>freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAI L]
          >Is it worth distinguishing free bytes from available bytes? I've never
          >seen them differ, and I'm not sure how they ever would...
          >>
          > import os
          > import statvfs
          >>
          > def free_bytes(path ):
          > stats = os.statvfs(path )
          > return stats[statvfs.F_BSIZE] * stats[statvfs.F_BFREE]
          >>
          > def avail_bytes(pat h):
          > stats = os.statvfs(path )
          > return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAI L]
          >>
          > if __name__ == '__main__':
          > import sys
          > for path in sys.argv[1:]:
          > print "%s:" % path,
          > print "%dK free," % (free_bytes(pat h) / 1024),
          > print "%dK available" % (avail_bytes(pa th) / 1024)
          >
          >
          Chris,
          Much thanks. That's just what I need.
          >
          Jeff,
          Not sure what's taking up the "available" space, but it's about 12GB
          on my system.
          Interesting.
          Available space is how much you can actually access as a non-root user.
          Apparently (thank you Jean-Paul), space can be reserved for superuser
          use only; such space is "free," but not "available. "

          I'm not sure how superuser-only space would be reserved in the first
          place. I don't see anything relevant in the fdisk man page.

          Comment

          • Christian Heimes

            #6
            Re: linux disc space

            Jeff Schwab wrote:
            I'm not sure how superuser-only space would be reserved in the first
            place. I don't see anything relevant in the fdisk man page.
            man mkfs

            :)

            Christian

            Comment

            • Matthew Woodcraft

              #7
              Re: linux disc space

              In article <iuudnTXnNsFPci janZ2dnUVZ_tmhn Z2d@comcast.com >,
              Jeff Schwab <jeff@schwabcen ter.comwrote:
              Available space is how much you can actually access as a non-root user.
              Apparently (thank you Jean-Paul), space can be reserved for superuser
              use only; such space is "free," but not "available. "
              I'm not sure how superuser-only space would be reserved in the first
              place. I don't see anything relevant in the fdisk man page.
              Look at mkfs.<whatever-your-filesystem-is>

              -M-

              Comment

              • Steve Holden

                #8
                Re: linux disc space

                Jeff Schwab wrote:
                I'm not sure how superuser-only space would be reserved in the first
                place. I don't see anything relevant in the fdisk man page.
                The UFS and ext2 filesystem space allocation routines become very
                inefficient when free space gets too low, so for regular uses the
                filesystem is considered full before that threshold is reached. You can
                adjust the threshold setting (amon others) with tunefs.

                Root uid processes can continue to use disk space after that point so
                that various daemon processes don't stop, and so that recovery actions
                can be taken.

                regards
                Steve
                --
                Steve Holden +1 571 484 6266 +1 800 494 3119
                Holden Web LLC http://www.holdenweb.com/

                Comment

                • Jeff Schwab

                  #9
                  Re: linux disc space

                  Steve Holden wrote:
                  Jeff Schwab wrote:
                  >I'm not sure how superuser-only space would be reserved in the first
                  >place. I don't see anything relevant in the fdisk man page.
                  >
                  The UFS and ext2 filesystem space allocation routines become very
                  inefficient when free space gets too low, so for regular uses the
                  filesystem is considered full before that threshold is reached. You can
                  adjust the threshold setting (amon others) with tunefs.
                  Live and learn. I've been using primarily reiserfs for a while now,
                  which may be why my free blocks always == available blocks.
                  Root uid processes can continue to use disk space after that point so
                  that various daemon processes don't stop, and so that recovery actions
                  can be taken.

                  Comment

                  • Tobiah

                    #10
                    Re: linux disc space

                    DataSmash wrote:
                    I simply want to capture the free disc space in a variable so that I
                    can compare changes. I'm aware of a few commands like "df -h" or "du -
                    k", but I can't figure out how to capture those values as a variable.
                    I also looked at os.statvfs(), but that output doesn't seem to make
                    any sense at all to me, knowing the size of the disc.
                    Thanks for your help!
                    R.D.
                    You could use the subprocess module to capture the output
                    of your disk usage commands.

                    --
                    Posted via a free Usenet account from http://www.teranews.com

                    Comment

                    Working...