How To Find The Folder Size In Linux Command Line And Sort It By Size

In this Linux Tip, let us see how to find the file and folder size in Linux Command Line and display the folders based on their size in the Terminal.

To put it short, du (disk usage) is the command used to view the folder size. Let’s see how to use different params of the du command below.

View List of files And Folders

ls -lah returns the list of folders, files, and their size. ls command returns the correct size of the files but it always returns the folder size as 4KB, irrespective of its actual size.

ls -lah

du, on the other hand, displays only the folder size and skips the files from the result set.

The commands in this article are executed at the Anaconda installation folder

Executing the du command without any params displays the size of the folders in the current directory and also its subfolders. In my test folder, this returns 44 K lines as output and this may not be the intended result in all cases. Let us see how to pass some additional params to get meaningful output.

grep lines

Folder Size In Linux

Execute the below commands in Linux Terminal

# To view the combined size of all folders
# cumulative, summary, human-readable 
du -csh

# To view the size of the top-level folders
du -ch --max-depth=1

# Display by folder size min to max
du -ch --max-depth=1 | sort -h

# Display by folder size max to min
du -ch --max-depth=1 | sort -hr

du

Leave a comment