Definition of Linux Size
The size command in Linux will allow to list the section size and the total size of the object files or the archived files in its argument list. When we do not specify the object file in the parameter list, then by default, ‘a.out’ file is used. In this tutorial, we will discuss its syntax, how to size command is used in Linux, its options, and their usages with different examples.
Syntax of size command in Linux:
We can use 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 command 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 along with its description.
Options | Description |
-A|-B –format={sysv|berkeley} | We can select the output style by mentioning the format either in SysV or Berkeley. By default, if no format is mentioned then it takes 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 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 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
When there is no file name passed in the argument, then a.out file is used as deafult file name as shown below. In the current directory, it will check for ‘a.out’ file and will calculate the size and it will display the result in Berkeley format.
Syntax:
size
Example:
size
3. To Get the Output in SysV Format
The output when generated in SysV format, it 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, then we will get the result in decimal value format as given in the below example.
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, then we will get the result in octal value format as given in below example.
Syntax:
size -o dir_name
Example:
size -o /usr/var/log
6. To Specify the Output Value in Hex Format
When we pass the option ‘-x’ with the argument list, then we will get the result in hex value format as given in below example.
Syntax:
size -x dir_name
Example:
size -x /usr/var/log
7. Option –radix
Radix option in size command is used to specify the format number instead of using decimal, hex or octal. For decimal, 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 size command is used to specify the format number instead of using decimal, hex, or octal. For decimal, we can use the number format as –radix=10.
Syntax:
size –radix=10 /dir_name
Example:
- Radix option in 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 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 any other format numbers, then we will get an error saying “Invalid radix”. Below is an example for 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 symbol that is present 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. The result that would be produced in using -t option is shown as below.
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 to list the section size and the total size of the object files or the archived files in its argument list. When we do not specify the object file in the parameter list, then by default, ‘a.out’ file is used. Different formats are used in displaying the output formats like decimal, octal, or hex. Options with examples are also explained in the above tutorial for better understanding.
Recommended Articles
This is a guide to Linux Size. Here we also discuss the definition and how does size command work in linux? along with different examples and its code implementation. You may also have a look at the following articles to learn more –
16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion
4.5
View Course
Related Courses