View total disk usage
Disk free space can be checked in the Linux command line using the
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 -hCode language: PHP (php)
Disk usage by folder
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 -hCode language: PHP (php)
Disk usage of files
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=1Code language: PHP (php)