Monitor disk usage with python

The module to use in python2 is statvfs imported from os

import os
statvfs = os.statvfs('/')
statvfs.f_frsize * statvfs.f_blocks     # Size of filesystem in bytes
statvfs.f_frsize * statvfs.f_bfree      # Actual number of free bytes
statvfs.f_frsize * statvfs.f_bavail     # Number of free bytes that ordinary users

NB: it is deprecated in python3, the module to use will be fstat os.fstat

Source:

Better usage:

Comments

Comments powered by Disqus