20% OFF Dedicated Servers for the first 12 months of service!

USE COUPON CODE: Q22018

Ends June 30, 2018

*T&C Apply

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:

Process

  1. Connecttoyourserverusing an ssh client such as PuTTY.
  2. Run the following command to find out current disk usage on the server

df –h

In the output, look for the entry for root (/) partition. In the following example, the available disk space is 5.7 G.

disk-space-usage1

  1. Change directory (cd) to the root (/) directory and run following commands:

cd /

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.

disk-space-usage2

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.

 

  1. Repeat steps 3 and 4 until you find the directory that is using the most disk space.

 

Tips:

  • 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:

cPanel/WHM

            du –sh /backup

Plesk

            du –sh /var/lib/psa/dumps

  • You can delete old log files from /var/log directory to free up some space quickly.