Igo*_*any 9 python macos file filesize sparse-file
我在python中创建稀疏文件如下:
>>> f = open('testfile', 'ab')
>>> f.truncate(1024000)
>>> f.close()
Run Code Online (Sandbox Code Playgroud)
文件完成后,占用0个磁盘空间,但其inode大小设置为我的截断值(1000K):
igor47@piglet:~/test$ ls -lh testfile
-rw-r--r-- 1 igor47 igor47 1000K 2010-07-09 04:02 testfile
igor47@piglet:~/test$ du -hs testfile
0 testfile
Run Code Online (Sandbox Code Playgroud)
如何在python中获取文件的实际空间使用量(分配大小)?该stat调用返回文件的表观大小,我不知道如何获得除了读取整个文件之外的其他实际用法(它可能会变得非常大)
>>> os.stat('testfile').st_size
1024000
Run Code Online (Sandbox Code Playgroud)
wum*_*ump 12
>>> os.stat('testfile').st_blocks*512
0
Run Code Online (Sandbox Code Playgroud)
Tadaa :)
st_blocks是实际分配给文件的512字节块的数量.请注意,st_blocks不保证在所有操作系统中都存在,但那些支持稀疏文件的操作系统通常会这样做.
| 归档时间: |
|
| 查看次数: |
3374 次 |
| 最近记录: |