10 UNIX / Linuz Size Command Examples for ObjectFiles

Linux size is part of GNU binutils.

This utility is very helpful for programmers to analyze the data from the executable files (or object files).

By default, this will provide the section size, total size for the given file name.

1. Default Size Output

By default the size command displays the output which has the size information in 5 different values (text, data, bss, dec and hex) as shown below.

# size /usr/bin/rsync
   text    data     bss     dec     hex filename
 389221   18728   71640  479589   75165 /usr/bin/rsync

The above format is in Berkeley format. All of the following three commands are the exact same.

size /usr/bin/rsync
size -B /usr/bin/rsync
size --format=Berkeley /usr/bin/rsync

2. Default File is a.out

If you don’t specify a file name as the argument, it will use a.out as the filename as shown below.

This will look for a.out in the current directory, and calculate the size value for this object file and display the output in the Berkeley format as shown below:

# size
   text    data     bss     dec     hex filename
   1040     484      16    1540     604 a.out

Also, if the given file is not a binary object file, it will thrown the following File format not recognized error message:

# size /root/backup_script
size: /root/backup_script: File format not recognized

3. Display Output in SysV Format

The SysV format have more detailed information in the output. This will display the details of various sections and the size and address of each and every one of the section name.

# size --format=SysV /usr/bin/rsync
/usr/bin/rsync  :
section                size      addr
.interp                  28   4194816
.note.ABI-tag            32   4194844
.note.gnu.build-id       36   4194876
.gnu.hash                68   4194912
.dynsym                4440   4194984
.dynstr                1809   4199424
.gnu.version            370   4201234
.gnu.version_r          160   4201608
...
....
.dynamic                432   6681256
.got                      8   6681688
.got.plt               1416   6681696
.data                 16832   6683136
.bss                  71640   6699968
.gnu_debuglink           16         0
Total                479605

4. Specify Output Value Format (Dec, Oct, or Hex)

By default the size command will display the output in the decimal format (-d option). Both of the following command will produce the same output.

# size /usr/bin/rsync

# size -d /usr/bin/rsync
   text    data     bss     dec     hex filename
 389221   18728   71640  479589   75165 /usr/bin/rsync

The following will generate the output in the ocal format. Also, this will display the “oct” column instead of the “dec” column in the output.

# size -o /usr/bin/rsync
   text    data     bss     oct     hex filename
01370145         044450 0213730 1650545   75165 /usr/bin/rsync

You can also combine the the format (Berkley or SysV) with this octal format as shown below.

# size -Ao /usr/bin/rsync
/usr/bin/rsync  :
section                  size        addr
.interp                   034   020001000
.note.ABI-tag             040   020001034
.note.gnu.build-id        044   020001074
.gnu.hash                0104   020001140
.dynsym                010530   020001250
..
..
.dtors                    020   031371220
.jcr                      010   031371240
.dynamic                 0660   031371250
.got                      010   031372130
.got.plt                02610   031372140
.data                  040700   031375000
.bss                  0213730   031435700
.gnu_debuglink            020          00
Total                01650565

The following will generate the output in the Hex format. Also, this will display the “hex” column instead of the “dec” column in the output.

# size -x /usr/bin/rsync
   text    data     bss     dec     hex filename
0x5f065  0x4928 0x117d8  479589   75165 /usr/bin/rsync

You can also combine the the format (Berkley or SysV) with this hex format as shown below.

# size -Ao /usr/bin/rsync

# size -Ax /usr/bin/rsync
/usr/bin/rsync  :
section                 size       addr
.interp                 0x1c   0x400200
.note.ABI-tag           0x20   0x40021c
.note.gnu.build-id      0x24   0x40023c
.gnu.hash               0x44   0x400260
.dynsym               0x1158   0x4002a8
..

5. Use radix Option for Output Format

Instead of -d, -o and -x, you can also use –radix and specify the number for the format as shown below:

For decimal:

# size -d /usr/bin/rsync

# size --radix=10 /usr/bin/rsync
   text    data     bss     dec     hex filename
 389221   18728   71640  479589   75165 /usr/bin/rsync

For octal:

# size -o /usr/bin/rsync

# size --radix=8 /usr/bin/rsync
   text    data     bss     oct     hex filename
01370145         044450 0213730 1650545   75165 /usr/bin/rsync

For hex:

# size -x /usr/bin/rsync

# size --radix=16 /usr/bin/rsync
   text    data     bss     dec     hex filename
0x5f065  0x4928 0x117d8  479589   75165 /usr/bin/rsync

Only 10,8 and 16 are valid numbers. Everything else will display the “Invalid radix” erroras shown below:

# size --radix=32 /usr/bin/rsync
size: Invalid radix: 32
size: supported targets: elf64-x86-64 elf32-i386 a.out-i386-linux pei-i386 
      pei-x86-64 elf64-l1om elf64-little elf64-big elf32-little 
	  elf32-big srec symbolsrec verilog tekhex binary ihex

6. Display Common Symbols Count

The common will display the total count of all common symbols in the file. In the default format (berkeley format), this is already included in the “bss” column value.

So, this option is helpful only in the SysV format (-A). As shown below, the last line that starts with *COM* shows this value.

# size -A --common /usr/bin/myprogram
/usr/bin/rsync  :
section                size      addr
.interp                  28   4194816
.note.ABI-tag            32   4194844
.note.gnu.build-id       36   4194876
..
..
.got.plt               1416   6681696
.data                 16832   6683136
.bss                  71640   6699968
.gnu_debuglink           16         0
*COM*                     5   6699784
Total                939605

7. Display Total in Berkely Format

Using -t option (or –totals), we can display a new line at the bottom of the output, which will display the total values of all the files listed in the output as shown below.

# size -t /usr/bin/to*
   text    data     bss     dec     hex filename
   7932     884      24    8840    2288 /usr/bin/toe
  55893    3040   12960   71893   118d5 /usr/bin/top
  63825    3924   12984   80733   13b5d (TOTALS)