리눅스 size 명령어 - linugseu size myeonglyeong-eo

저도 EC2에서 적은 용량의 스토리지만 사용하여 Ubuntu를 운용하다가 디스크 공간이 부족하여 파일 복사가 되지 않거나 디렉터리 이동이 되지 않는 문제가 발생했던 적이 종종 있습니다.

이럴 때 가장 좋은 방법은 스토리지의 크기을 늘려주는 방법입니다. 

EC2를 쓰고 있다면 EC2에 연결된 EBS의 크기를 클릭 몇 번으로 확장할 수가 있지만, 물리 HDD를 쓰고 있을 때는 용량 확장이 까다롭습니다. 또 클라우드를 쓸 때는 비용 절감 문제로 디스크 공간 확보가 어려울 수가 있습니다.

디스크 공간을 확장하기전에 어떤 파일이 용량을 가장 크게 차지하는지, 또는 불필요하게 큰 용량을 차지하는 로그 데이터들이나 더미 데이터들이 있는지 확인해보면 좀 더 현명하게 스토리지의 공간을 관리할 수 있습니다.

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.

All in One Software Development Bundle(600+ Courses, 50+ projects)

리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo

리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo
리눅스 size 명령어 - linugseu size myeonglyeong-eo

Price
View Courses

600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (83,348 ratings)

Syntax of size command in Linux:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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.

OptionsDescription-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        –totalsTo print the total size for Berkeley format only.–commonTo 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        –helpTo display the list of options available in size command.-v        –versionTo 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

리눅스 size 명령어 - linugseu size myeonglyeong-eo

The above result is in Berkeley format and we can also get the same output in three different commands as shown below:

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 directory_name0

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 directory_name1

Example:

size directory_name2

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 directory_name3

Example:

size directory_name4

리눅스 size 명령어 - linugseu size myeonglyeong-eo

  • 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 directory_name3

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 directory_name6

Example:

size directory_name0

리눅스 size 명령어 - linugseu size myeonglyeong-eo

  • 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 directory_name8

Example:

size directory_name9

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 /usr/var/log0

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 /usr/var/log1

Example:

size /usr/var/log2

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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 /usr/var/log3

Example:

size /usr/var/log4

리눅스 size 명령어 - linugseu size myeonglyeong-eo

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.

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 –