To check disk usage on your server, you can use several command-line tools available in most Unix-based systems (like Linux and macOS). These tools help you monitor how much disk space is being used, what’s taking up space, and how much free space remains. This is essential for managing server health, especially for avoiding downtime due to full disks.
1. Using the df
Command
The df
(disk free) command shows how much space is used and available on mounted filesystems.
Basic usage:
df -h
Explanation:
-h
stands for “human-readable,” and it displays sizes in KB, MB, or GB.- This shows a list of mounted filesystems, their total size, used space, available space, and usage percentage.
Sample output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 25G 23G 53% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
This tells you how much space is being used on each mounted partition (e.g., /
is the root directory).
2. Using the du
Command
The du
(disk usage) command shows how much space individual files and directories are using.
Check space in a directory:
du -sh /path/to/directory
Explanation:
-s
summarizes the total.-h
makes it human-readable.
To view usage of all folders in a directory:
du -h --max-depth=1 /path
This breaks down disk usage for each subdirectory inside /path
.
Example output:
1.1G /home/user/Documents
200M /home/user/Downloads
This is very helpful when tracking down what’s consuming disk space.
3. Combining du
with sort
You can sort folders by size to find the biggest ones:
du -h /path | sort -hr | head -n 10
sort -hr
: Sorts in human-readable format, largest first.head -n 10
: Shows the top 10 results.
This helps locate space hogs quickly.
4. Graphical Alternatives
If you’re using a desktop environment, tools like ncdu (for terminal-based interactive browsing) can help:
Install and use ncdu
on Ubuntu based servers:
sudo apt install ncdu
ncdu /
It shows a navigable summary of disk usage by folder.
5. Checking Disk Inodes
Disk space may be free, but you could still run out of inodes (used to track files). Check inode usage with:
df -i
Final Thoughts
For quick checks, use df -h
. For detailed usage by directory, use du -sh
or ncdu
. Regular disk checks can help avoid outages or performance issues due to full storage.
Sponsored
Check out vertahost.com for all of your web hosting needs, including 24/7 support, and server expertise