This can be done using the statvfs
system call. In Python (both 2 and 3), this can be accessed using os.statvfs
. The call describes the filesystem containing the file/directory the path specifies.
So to get the number of free inodes, use
#import osos.statvfs('/some/directory').f_favail
Also, it's possible that some percentage of the inodes are reserved for the root user. If the script is running as root and you want to allow it to use the reserved inodes, use f_ffree
instead of f_favail
.