How to Check Disk Usage on Your Dedicated Server
Monitoring disk usage on your server is essential for maintaining its health and ensuring that your applications run smoothly. If your disk space is running low, it could lead to performance issues or even cause your applications to crash. In this guide, we’ll show you how to check disk usage on your dedicated server to keep everything in top condition.
Step 1: Access Your Dedicated Server
To check disk usage, you first need to log into your dedicated server via SSH (Secure Shell).
-
Open your terminal or SSH client.
-
Log in to your server by running the following command:
ssh username@your-server-ip
Replace
usernamewith your server’s user account andyour-server-ipwith the IP address of your server. -
Enter your password when prompted.
Step 2: Use the df Command to Check Disk Usage
Once logged in, you can use the df command to check disk space on your server. This command provides a summary of disk usage for all mounted filesystems.
-
Run the
dfcommand:df -h
The
-hflag stands for "human-readable" format, which shows the disk space in a more understandable format (KB, MB, GB, etc.). -
Review the output: The output will look like this:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 30G 40% / /dev/sdb1 100G 45G 55G 45% /dataHere’s what each column means:
- Filesystem: The name of the disk partition.
- Size: The total disk size.
- Used: The amount of disk space that’s already used.
- Avail: The available disk space.
- Use%: The percentage of disk space used.
- Mounted on: The directory where the disk is mounted.
Step 3: Check Disk Usage for Specific Directories
If you need more detailed information about which directories are consuming the most disk space, you can use the du command.
-
Run the
ducommand to see disk usage for a specific directory:du -sh /path/to/directory
Replace
/path/to/directorywith the path of the directory you want to check.The
-sflag gives you the summary of the disk usage for the entire directory, while the-hflag makes the output human-readable. -
Example:
du -sh /var/www
Output:
5.6G /var/wwwThis shows that the
/var/wwwdirectory is using 5.6 GB of disk space.
Step 4: Use ncdu for a More Interactive View (Optional)
For a more interactive way to explore disk usage, you can use the ncdu (NCurses Disk Usage) command. This tool provides a visual, navigable representation of disk usage.
-
Install
ncdu:- For Ubuntu/Debian:
sudo apt install ncdu
- For CentOS/RHEL:
sudo yum install ncdu
- For Ubuntu/Debian:
-
Run
ncdu:ncdu /path/to/directory
Replace
/path/to/directorywith the directory you want to analyze, or simply runncduto analyze the root directory.Use the arrow keys to navigate and explore which files or directories are consuming the most space.
Step 5: Set Up Disk Space Alerts (Optional)
To prevent your server from running out of disk space, consider setting up alerts to notify you when disk usage exceeds a certain threshold.
- Install the
monitmonitoring tool: - For Ubuntu/Debian:
sudo apt install monit
- For CentOS/RHEL:
sudo yum install monit
-
Configure
monitto monitor disk usage:-
Edit the
monitconfiguration file:sudo nano /etc/monit/monitrc
-
Add the following to monitor disk usage:
check filesystem root with path / if space usage > 90% then alert -
This configuration sends an alert when disk usage exceeds 90%.
-
-
Restart
monitto apply changes:sudo service monit restart
Step 6: Clean Up Unnecessary Files
If you notice that disk usage is too high, you can clean up unnecessary files to free up space.
-
Clean up old logs:
- Check the
/var/logdirectory for old log files and remove them if they are no longer needed.sudo rm /var/log/*.log
- Check the
-
Remove unused packages:
- For Ubuntu/Debian:
sudo apt autoremove
- For CentOS/RHEL:
sudo yum autoremove
- For Ubuntu/Debian:
-
Delete unnecessary backups or other large files that are no longer required.
Conclusion
Regularly checking your disk usage is vital for maintaining a healthy server environment. By following the steps in this guide, you can monitor your server’s disk space and avoid any performance or stability issues caused by running out of disk space. Use tools like df, du, and ncdu to keep track of disk usage and take action when necessary to keep your server running smoothly.
