shows size of the file (when you open and read it, that's how many bytes you will get)
ls -la | grep vmlinux
-rwxr-xr-x 1 root root 8167158 May 21 12:14 vmlinux
du -h vmlinux
3.8M vmlinux
size vmlinux
text data bss dec hex filename
2221248 676148 544768 3442164 3485f4 vmlinux
shows actual disk usage which can be smaller than the file size due to holes
shows the size of the runtime image of an object既然它们都显示出不同的大小,哪一个最接近实际的图像大小? 为什么它们会不同?
ls
du
size
我正在编译一个自定义内核,我想测试一下图像文件的大小。这些都是结果:ls -la可执行文件,这和文件的大小没有直接关系(bss无论多大,文件中都不使用字节,文件中可能包含不属于运行时镜像的调试信息等)。如果你想知道一个可执行文件不包括动态内存分配会占用多少RAMROM。size
给你提供你需要的信息。
需要了解两个定义
1运行时间与存储时间(这就是为什么 size
不同)
2文件深度与目录(这就是为什么 du
不同)
请看下面的例子。
[root@localhost test]# ls -l
total 36
-rw-r--r-- 1 root root 712 May 12 19:50 a.c
-rw-r--r-- 1 root root 3561 May 12 19:42 a.h
-rwxr-xr-x 1 root root 71624 May 12 19:50 a.out
-rw-r--r-- 1 root root 1403 May 8 00:15 b.c
-rw-r--r-- 1 root root 1403 May 8 00:15 c.c
[root@localhost test]# du -abch --max-depth=1
1.4K ./b.c
1.4K ./c.c
3.5K ./a.h
712 ./a.c
70K ./a.out
81K .
81K total
[root@localhost test]# ls -l
total 36
-rw-r--r-- 1 root root 712 May 12 19:50 a.c
-rw-r--r-- 1 root root 3561 May 12 19:42 a.h
-rwxr-xr-x 1 root root 71624 May 12 19:50 a.out
-rw-r--r-- 1 root root 1403 May 8 00:15 b.c
-rw-r--r-- 1 root root 1403 May 8 00:15 c.c
[root@localhost test]# size a.out
text data bss dec hex filename
3655 640 16 4311 10d7 a.out
如果使用 size
不在可执行范围内。操作系统 将报告一个错误。