Skip to content Skip to sidebar Skip to footer

How To Find The Inode Of All Files In Linux With Python?

#!/usr/bin/python import os, sys # Open a file fd = os.open( 'foo.txt', os.O_RDWR|os.O_CREAT ) # Now get the touple info = os.fstat(fd) print 'File Info :', info # Now get

Solution 1:

The os.stat function returns directory information about a file. The inode is stored in st_ino field. Here's some code to get you started:

>>> import glob
>>> import os
>>> for filename in glob.glob('*.py'):
        print(os.stat(filename).st_ino, filename)

To get the filesize, use the st_size field:

>>> os.stat(filename).st_size       
1481

To get the filename, just print the filename variable:

>>> print(filename)
'hello.py'

Post a Comment for "How To Find The Inode Of All Files In Linux With Python?"