473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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.
Feb 15 '08 #1
9 3077
On Feb 15, 7:10 pm, DataSmash <r...@new.rr.comwrote:
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_BAVAIL]

HTH,
Chris
Feb 15 '08 #2
Chris wrote:
On Feb 15, 7:10 pm, DataSmash <r...@new.rr.comwrote:
>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_BAVAIL]
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(path):
stats = os.statvfs(path)
return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

if __name__ == '__main__':
import sys
for path in sys.argv[1:]:
print "%s:" % path,
print "%dK free," % (free_bytes(path) / 1024),
print "%dK available" % (avail_bytes(path) / 1024)
Feb 15 '08 #3
On Feb 15, 1:32 pm, Jeff Schwab <j...@schwabcenter.comwrote:
Chris wrote:
On Feb 15, 7:10 pm, DataSmash <r...@new.rr.comwrote:
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_BAVAIL]

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(path):
stats = os.statvfs(path)
return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

if __name__ == '__main__':
import sys
for path in sys.argv[1:]:
print "%s:" % path,
print "%dK free," % (free_bytes(path) / 1024),
print "%dK available" % (avail_bytes(path) / 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.
Feb 15 '08 #4
DataSmash wrote:
On Feb 15, 1:32 pm, Jeff Schwab <j...@schwabcenter.comwrote:
>Chris wrote:
>>On Feb 15, 7:10 pm, DataSmash <r...@new.rr.comwrote:
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_BAVAIL]
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(path):
stats = os.statvfs(path)
return stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]

if __name__ == '__main__':
import sys
for path in sys.argv[1:]:
print "%s:" % path,
print "%dK free," % (free_bytes(path) / 1024),
print "%dK available" % (avail_bytes(path) / 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.
Feb 15 '08 #5
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

Feb 15 '08 #6
In article <iu******************************@comcast.com>,
Jeff Schwab <je**@schwabcenter.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-

Feb 15 '08 #7
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/

Feb 15 '08 #8
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.
Feb 15 '08 #9
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

Feb 18 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Thomas Schulz | last post by:
Any ideas how to check for free disc space from Python. Platform independent? Thanks for any suggestion. Thomas
1
by: J-miami | last post by:
I am just starting to learn Perl. I had an idea that there should be free open-source Internet Cafe management software for Linux. I searched around online but couldn't find anything. The...
0
by: Ralf Gross | last post by:
Hi, I'm looking for the Net Search Extender version for linux. We have a company license for db2 and I got a white box with about 100 CDs in it. I think it's the 'development edition' (IBM DB2...
2
by: Rob | last post by:
Does anyone have any idea of any API that exists, or functions that others have created to find out the start cluster address of any particular file on a FAT32 formatted disc. I dont mind using...
5
by: Guenther Sohler | last post by:
How can I get the serial ID of the Hard disc , which is displayed during boot up - preferrably in C ; whithout having to communicate with the hard disc by myself with the IO registers ?
1
by: James | last post by:
After uppgrading from .NET v1.1 to .NET v2.0 we ca see massive usage of disc space(10 GB) in a subfolder in the following folder: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET...
4
by: John Salerno | last post by:
I'm interested in trying out Linux, probably Ubuntu, but I was wondering which distribution you guys like to use (because it's a pain trying to decide!) and you guys are smart. And to keep it...
2
DonRayner
by: DonRayner | last post by:
Hi all, I've been fighting with this problem for a couple of days and hopfully someone here has an answer. First off this is a comercial software package (JobBoss 5.02) using access 2000 runtime....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.