How to find out the size of a file and directory in Linux
Last updated: Jul 17, 2022
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
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
$. ls -lh --block-size=M test.sql
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
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
Thank you all, I hope that my article helped you in some way.