How to display the size of all directories in the current directory using the ls command in Linux?
Published on Aug. 22, 2023, 12:17 p.m.
The ls
command is not typically used to display the size of directories in Linux. However, you can use the du
command (short for “disk usage”) to display the sizes of directories in the current directory. Here is an example command:
du -sh */
This command will display the sizes of all directories in the current directory in human-readable format. The -s
option tells du
to display only a summary of the sizes for each directory, while the -h
option tells it to display the sizes in “human-readable” format (e.g. 1K, 12M, etc.). The */
syntax at the end of the command tells the shell to expand to all directories in the current directory.
The output will look similar to this:
4.0K directory1/
8.0K directory2/
2.3M directory3/
This output shows the size of each directory in the current directory in human-readable format (e.g. 4.0K, 8.0K, etc.). The name of each directory is also displayed at the end of each line.
Note that du
is a versatile command that can also be used to display the sizes of individual files or directories at any level of the filesystem. For more information on using the du
command, you can refer to its manual page by running man du
in your terminal.