0
0
Linux-cliHow-ToBeginner · 3 min read

How to Check Disk Usage in Linux: Simple Commands Explained

To check disk usage in Linux, use the df command to see free and used space on all mounted filesystems. For detailed folder or file size, use the du command.
📐

Syntax

The df command shows disk space usage of mounted filesystems. The du command shows disk usage of files and directories.

  • df [options]: Displays disk space usage summary.
  • du [options] [path]: Shows size of files and directories at the given path.
bash
df -h

du -sh /path/to/directory
💻

Example

This example shows how to use df -h to display disk usage in a human-readable format and du -sh to check the size of your home directory.

bash
df -h

du -sh ~
Output
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% / /dev/sda2 100G 60G 40G 60% /home 12G /home/username
⚠️

Common Pitfalls

Common mistakes include:

  • Using df to check folder sizes instead of filesystem usage.
  • Not using the -h option, which makes output hard to read.
  • Running du without -s can produce too much output.
bash
df

du /home/username

# Better way:
df -h

du -sh /home/username
📊

Quick Reference

CommandDescriptionCommon Option
dfShows disk space usage of filesystems-h (human-readable sizes)
duShows disk usage of files and directories-sh (summary, human-readable)
lsblkLists block devices and their sizes-f (shows filesystem info)

Key Takeaways

Use df -h to quickly see disk space usage of all mounted filesystems.
Use du -sh [path] to check the size of a specific directory or file.
Always add -h for human-readable sizes to make output easier to understand.
Avoid using df to check folder sizes; it shows filesystem usage instead.
Use du -s to get a summary instead of a long list of sizes.