在qnx上使用du命令统计目录大小时,发现统计数值与实际大小不一样。
比如目录下有个已知1gb大小的问题,但du统计出来的值跟1gb差太多了
# ls -al
total 2097169
drwxrwxrwx 2 root root 4096 Jan 01 00:21 .
drwxrwxrwx 6 root root 4096 Jan 01 00:07 ..
-rw-r--r-- 1 root root 1073741825 Jan 01 00:21 1gb.bin
# du -s
2097161 .
查看qnx关于du命令的文档
The space figures are displayed in 512-byte blocks by default. If you want du to print the size in bytes, you specify the -p option. The sizes output by du when you specify the -p option are accurate with one exception. The numbers may be slightly higher than expected because they include extent blocks that are part of filesystem overhead associated with the file, but don’t contain actual data.
If you specify nondirectories, they aren’t listed unless you specify the -a option.
Files with multiple links are reported only once.
与Linux不同的是,du -s显示的大小是以512byte为单位的,也就是说du -s的值x512后等于实际大小。如果想直接以1byte为单位显示,把-s参数改为-p参数即可。
# ls -al
total 2097169
drwxrwxrwx 2 root root 4096 Jan 01 00:21 .
drwxrwxrwx 6 root root 4096 Jan 01 00:07 ..
-rw-r--r-- 1 root root 1073741825 Jan 01 00:21 1gb.bin
# du -p
1073746432 .