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 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
Since all of them show different sizes, which one is closest to the actual image size? Why are they different?
ls is reporting the allocated size; du is reporting the amount of space actually used. As your torrent client downloads more it will fill in the gaps and the du -reported size will grow to match what ls reports.
Usage notes du computes file space in units of 512 bytes. The actual disk space that is used by files and directories might be more, since some systems allocate space in units of some multiple of a sector. On UNIX System V, it is usually two sectors; on UNIX Version 7, it is one sector.
Using the ls Command –l – displays a list of files and directories in long format and shows the sizes in bytes. –h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes. –s – displays a list of the files and directories and shows the sizes in blocks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With