View total disk usage

Disk free space can be checked in the Linux command line using the df and du commands. df stands for disk free. du stands for disk usage. The -h flag stands for human. It shows the sizes in human readable formats like MB or GB instead of bytes.

1
2
# Show total disk usage
df -h

Disk usage by folder

The s flag stands for sum. It shows the total space taken by the current folder including its sub-folders. Including the s flag shows the total size taken up by a folder while using du command without it shows the list of files/folders and their sizes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Show disk usage of current folder including sub-folders
du -sh

# Show disk usage of specified folder
du -sh folder-name

# List disk usage of first-level sub-folders in the current folder
du -h --max-depth=1

# List disk usage of ALL sub-folders in the current folder
du -h

Disk usage of files

The a flag stands for all. It lists the disk usage of all the files and folders (including sub-folders) in the current directory.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

# List disk usage of ALL files & folders in the current folder
du -a

# Combine with 'h' flag for file & folder sizes in simplified formats  
du -ah

# Combine with --max-depth for sizes of nth-level files & folders
du -ah --max-depth=1