@localhost ~]# dd of=sparse-file bs=1k seek=5120 count=0 0+0 records in 0+0 records out 0 bytes (0 B) -rw-r--r--. 1 root root 5242880 Nov 8 11:32 sparse-file [root@localhost ~]# ls -ls sparse-file 0 -rw-r --r--. 1 root root 5242880 Nov 8 11:32 sparse-file // 而 sparse-file 占用的存储空间为 0 个 block [root@localhost ~]# du sparse-file 0 sparse-file [root@localhost ~]# du -h sparse-file 0 sparse-file 此时若用 vim 打开该文件 staff 5242880 11 9 09:44 sparse-file ➜ ~ du sparse-file 10240 sparse-file 以上是用 dd 等命令创建稀疏文件,也有同学用
@localhost ~]# dd of=sparse-file bs=1k seek=5120 count=0 0+0 records in 0+0 records out 0 bytes (0 B) -rw-r--r--. 1 root root 5242880 Nov 8 11:32 sparse-file [root@localhost ~]# ls -ls sparse-file 0 -rw-r --r--. 1 root root 5242880 Nov 8 11:32 sparse-file // 而 sparse-file 占用的存储空间为 0 个 block [root@localhost ~]# du sparse-file 0 sparse-file [root@localhost ~]# du -h sparse-file 0 sparse-file 此时若用 vim 打开该文件 9 09:44 sparse-file ➜ ~ du sparse-file 10240 sparse-file 以上是用 dd 等命令创建稀疏文件, 也有同学用 c 代码实现了相同的功能。
用 dd 命令生产一个文件, 上例中为从标准输入中读取 count=0 个block, 输出到 sparse-file 中, 一个 block 的大小为1k(bs=1k), 输出时先将写指针移动到 seek