使用截断创建巨大文件 - df 未显示可用空间减少

Car*_*don 6 linux filesystems

我正在尝试测试我们设置的磁盘空间监视器。为此,我运行了该命令,truncate -s 125G /publish/data/bigFile该命令应该占用足够的空间来触发警报。

但是, df -h 显示该分区:( /dev/vdb1 196G 66G 121G 36% /publish/data 也就是说,运行 truncate 命令后可用空间没有改变。)

ls -lh文件上显示: -rw-r--r-- 1 username users 126G Aug 7 11:27 /publish/data/bigFile

/publish/data 的挂载输出: /dev/vdb1 on /publish/data type ext4 (rw,relatime,data=ordered)

编辑:我也刚刚意识到,这些数字没有意义:196-66=130gb,那么为什么 df 首先说 121gb 免费?

sus*_*tus 6

无法看到任何支持它的文档,但truncate必须创建一个稀疏文件:

测试 truncate -s 10G testfile

du testfile # 显示占用的大小

   0  testfile
Run Code Online (Sandbox Code Playgroud)

du -h --apparent-size # 显示外观尺寸

   10G   testfile
Run Code Online (Sandbox Code Playgroud)

从 du 手册页:

   --apparent-size
          print   apparent  sizes,  rather  than  disk  usage;
          although the apparent size is  usually  smaller,  it
          may  be  larger  due  to  holes in ('sparse') files,
          internal fragmentation,  indirect  blocks,  and  the
          like
Run Code Online (Sandbox Code Playgroud)

错误定位

尝试使用fallocate,它非常快并且不会创建稀疏文件。

fallocate -l 125G filename
Run Code Online (Sandbox Code Playgroud)