Identify Disk Space Usage on a Linux Machine using Command Line
f your server runs out of disk space, critical services such as Apache and MySQL would crash. To identify what is using most of the disk, use following steps:
- Connecttoyourserverusing an ssh client such as PuTTY.
- Run the following command to find out current disk usage on the server
In the output, look for the entry for root (/) partition. In the following example, the available disk space is 5.7 G.
- Change directory (cd) to the root (/) directory and run following commands:
du -sk * 2>/dev/null | sort –nr
These command will list all the sub-directories in the root (/) directory, sorted by their size in kilo bytes.
Change directory (cd) to the directory that is the largest (/usr in the above example) and run the du -sk * 2>/dev/null | sort –nr command again to list the size of each sub-directories under that directory.
- Repeat steps 3 and 4 until you find the directory that is using the most disk space.
- If you have enabled backups on the control panel such as Plesk/cPanel, they may contribute to the high disk usage. Depending on the control panel you are using, you can use one following commands to find out disk used by the backup directory:
du –sh /backup
du –sh /var/lib/psa/dumps
- You can delete old log files from /var/log directory to free up some space quickly.