作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
#!/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/
我是一名优秀的程序员,十分优秀!