How to find out the size of a file and directory in Linux

  • Last updated: Oct 14, 2024
  • Views: 5
  • Author: Admin
How to find out the size of a file and directory in Linux

Colleagues hello to all.

In today's article we will talk about how you can quickly find out the size of a file and directories in Linux. You will learn how to view the size of a file through various commands and utilities.

 

The first option to view the size of a file is through the ls command.

$. ls -lh test.sql

linux_file_size

In this example, we are looking at the size file test.sql. As a result, the console tells us that the size of the test.sql file is 100 megabytes.

 

You can add the  --block-size option to the ls command so that you can explicitly specify in which unit of change to show the file size.

$. ls -lh --block-size=K test.sql

or

$. ls -lh --block-size=M test.sql

linux_file_size


 

For the following example, we will use the du command. The du command is specifically for viewing the size of files in a directory.

$. du -h test.sql

linux_file_size

 

In the following example, we will find out what the size of the directory itself is, for this we use the same command, but with the  -s parameter.

$. du -sh /app

linux_file_size


 

Thank you all, I hope that my article helped you in some way.

 

SIMILAR ARTICLES