473,671 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3093
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
Feb 15 '08 #2
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)
Feb 15 '08 #3
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.
Feb 15 '08 #4
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.
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**@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-

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
4977
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
18002
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 program would be appealing to anyone wanting to offer Internet access to their customers, from Internet Cafes to hotels. Who wants to pay hundreds or thousands of dollars for Internet Cafe management software? If running Linux, one could put together...
0
1222
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 Universal DEV. ED. 8.1 Media Pack Deutsch). I successfully installed 8.1 with FP 10. In the box I found the Net Search Extender disc for Windows and Unix operation systems, but nothing for linux.
2
2769
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 linux to do this, as i presume windows would never allow low level access to the disc like this.
5
2639
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
1217
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 Files IIS6 on Windows 2003 server web edition. This site contains a few hundred page and approximately 50 concurrrent users. The amount of data in the Temporary ASP.NET Files has increased with 2 GB within last 2 hours. We dont understand why? ...
4
1748
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 Python related, I'll also ask, is there anything special I need to know about using Python on Linux? Do any things change, or can it be used just as I use it on Windows? Thanks!
2
5038
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. the main mdb file is now at 1.33gb. The software is locked so I can't get at anything to make any changes. Problem is occuring when accounting goes to close the month of septmber which will also close our year end (no choice) The program will run...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6237
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.