Updated June 30, 2023
Definition of Linux Size
The size command in Linux will allow listing the section size and the total size of the object files or the archived files in its argument list. In this tutorial, we will discuss its syntax, how to size command is used in Linux, its options, and its usages with different examples.
Syntax of size command in Linux:
We can use the size command in Linux in a different format with different options, as shown below:
size [-A|-B|--format=compatibility]
[--help]
[-d|-o|-x|--radix=number]
[--common]
[-t|--totals]
[--target=bfdname] [-V|--version]
[objfile...]
How Does Size Command Work in Linux?
Size commands in Linux can be used in different ways with its options. Below are the options that can be used with the size command in Linux and its description.
Options | Description |
-A|-B –format={sysv|berkeley} | We can select the output style by mentioning the format either in SysV or Berkeley. |
-o|-d|-x –radix={8|10|16} | To display the numbers in order of octal, decimal, or hex. |
-t –totals | To print the total size for Berkeley format only. |
–common | To print the total size of *COM* syms |
–target=<bfdname> | To set the binary object file format |
@<file> | To scan the options from object-file |
-h –help | To display the list of options available in the size command. |
-v –version | To display the version of the program. |
Examples of Linux Size Command
Following are the examples are given below:
1. To Get the Default Size Output
The size command will display the output that will give you information on the size command in 5 values like data, text, dec, bss, and hex as given below.
Syntax:
size directory_name
Example:
size /usr/var/log
The above result is in Berkeley format, and we can also get the same output in three different commands, as shown below:
2. Default File Option
In the current directory, it will check for ‘a.out’ file and calculate the size, displaying the result in Berkeley format.
Syntax:
size
Example:
size
3. To Get the Output in SysV Format
The output, when generated in SysV format, will print different sections along with the size and address of each section name.
Syntax:
size –format=SysV dir_name
Example:
size --format=SysV /usr/var/log
4. To Specify the Output Value in Decimal
When we pass the option ‘-d’ with the argument list, we will get the result in decimal value format as given in the example below.
Syntax:
size -d dir_name
Example:
size -d /usr/var/log
5. To Specify the Output Value in Octal Format
When we pass the option ‘-o’ with the argument list, we will get the result in octal value format as given in the example below.
Syntax:
size -o dir_name
Example:
size -o /usr/var/log
6. To Specify the Output Value in Hex Format
When we pass option ‘-x’ with the argument list, we will get the result in hex value format as given in the example below.
Syntax:
size -x dir_name
Example:
size -x /usr/var/log
7. Option –radix
For decimals, we can use the number format as –radix=10.
Syntax:
size –radix=10 /dir_name
Example:
size --radix=10 /usr/var/log
- Radix option in the size command is used to specify the format number instead of using decimal, hex, or octal. For decimals, we can use the number format as –radix=10.
Syntax:
size –radix=10 /dir_name
Example:
- Radix option in the size command is used to specify the format number instead of using decimal, hex or octal. For octal, we can use the number format as –radix=8.
Syntax:
size –radix=8 /dir_name
Example:
size -o /usr/var/log
- Radix option in the size command is used to specify the format number instead of using decimal, hex, or octal. For hex, we can use the number format as –radix=16.
Syntax:
size --radix=16 /dir_name
Example:
size --radix=16 /usr/var/log
We can use only format numbers as 10,8,16 for decimal, octal, and hex, respectively. When we use other format numbers, we will get an error saying “Invalid radix.” Below is an example of an invalid radix format.
size --redix=12 /usr/var/log
8. To Display the Common Symbol Count
The common option allows printing the total number of all common symbols in the object file. By default, the format will take Berkeley file format; this will also be used to include in the value for column “bss.”
Syntax:
size -A --common /dir_name
Example:
size -A --common /usr/var/log
Option -A is used for SysV format. In the above example, the last line having *COM* will give the value.
9. To Display the Total in Berkeley Format
The option -t (or –totals) allows in displaying the new line at the end of the result that will print the value of all the object files that are in the list.
Syntax:
size -t /dir_name
Example:
size -t /usr/var/lo*
Conclusion
The size command in Linux is a very important command that will allow listing the section size and the total size of the object files or the archived files in its argument list. When the object file is not specified in the parameter list, the default file name used is ‘a.out’. The output formats can be displayed in different formats, such as decimal, octal, or hexadecimal. The tutorial above explains various options and provides examples to enhance understanding of these output formats.
Recommended Articles
We hope that this EDUCBA information on “Linux Size” was beneficial to you. You can view EDUCBA’s recommended articles for more information.