file size using bash

Commands to get the size of a directory in Linux

To get the size of directories in Linux, you can use the ‘du’ (disk usage) command. The ‘du’ command displays the disk usage of files and directories. By default, it shows the sizes of directories and their subdirectories recursively. Here’s how you can use it.

Open a terminal and navigate to the directory for which you want to check the size. Then, run the following command:

du -sh <directory>

You will want to replace <directory> with the name or path of the directory you want to check. For example, if you want to check the size of a directory named “myfolder”, you would run:

du -sh myfolder

The ‘-s” option is used to display only the total size of the specified directory, rather than showing the size of each individual file and subdirectory within it.

the ‘-h’ option is used to display the size in human-readable format, such as kilobytes (k), megabytes (M), or gigabytes (G) depending on the directory size.

The above command will output the total size of the directory, including all its contents.