I was compiling a custom kernel, and I wanted to test the size of the image file. These are the results:
ls -la | grep vmlinux
-rwxr-xr-x 1 root root 8
They are all correct, they just show different sizes.
ls
shows size of the file (when you open and read it, that's how many bytes you will get)du
shows actual disk usage which can be smaller than the file size due to holessize
shows the size of the runtime image of an object/executable which is not directly related to the size of the file (bss uses no bytes in the file no matter how large, the file may contain debugging information that is not part of the runtime image, etc.)If you want to know how much RAM/ROM an executable will take excluding dynamic memory allocation, size
gives you the information you need.
Two definition need to be understood
1 runtime vs storetime (this is why size
differs)
2 file depth vs directory (this is why du
differs)
Look at the below example:
[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
If using size
not on executable, OS will report an error.