gpt4 book ai didi

python - 如何用Python查找Linux中所有文件的inode?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:00 25 4
gpt4 key购买 nike

#!/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 uid of the file
print "UID of the file :%d" % info.st_uid

# Now get gid of the file
print "GID of the file :%d" % info.st_gid

# Close opened file
os.close( fd)

最佳答案

os.stat函数返回有关文件的目录信息。 inode存储在 st_ino 字段中。下面是一些让您入门的代码:

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

要获取文件大小,请使用 st_size 字段:

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

要获取文件名,只需打印文件名变量:

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

关于python - 如何用Python查找Linux中所有文件的inode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48656460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com