Check disk usage in Linux command line

Add RSS feed to Reader and sync to Readwise.

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.

# Show total disk usage
df -h
Code language: PHP (php)

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.

# 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
Code language: PHP (php)

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.

# 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
Code language: PHP (php)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *