Introduction
This tutorial will guide you on how to analyze disk usage on your server using the df
and du
commands. These tools help you understand the available space on your file systems and the space used by individual directories.
We'll demonstrate this using Ubuntu 16.04, but the commands will be applicable to other distributions available on VPS SELL.
Update System
Before starting, ensure your server is up-to-date by running:
apt-get update
or
yum update
Using df
Command
The df
(disk free) command displays the available disk space on your file systems. Running df
without any arguments shows the disk space for all mounted file systems:
df
The output columns are:
- Filesystem: The storage name (e.g.,
/dev/sda1
).
- 1K-blocks: The total size of the file system in Kilobytes.
- Used: The space used.
- Available: The space free.
- Use%: The percentage of space used.
- Mounted on: The mount point of the file system.
For a more readable format, use the -h
option:
df -h
Additional useful flags include:
-T
: Adds a column for the file system type.
-l
: Shows only local file systems, excluding remote ones like NFS.
Using du
Command
The du
(disk usage) command provides detailed information about the space used by directories. To see space usage for directories:
du
For a more user-friendly output, use:
du -h
To get the total space used by a directory without details of subdirectories, use:
du -sh
If you find the output too verbose, use the following command to show only the space used by top-level directories:
du --max-depth=1 | sort -n | awk 'BEGIN {OFMT = "%.0f"} {print $1/1024,"MB", $2}'
Conclusion
The df
and du
commands are powerful tools for monitoring and managing disk usage. They help you identify large directories and files, making disk management easier. Explore the man
pages and help options for more advanced usage.