/
/
How to check free disk space

How to check free disk space

To check and analyze free disk space on Linux, you can use the built-in utilities as df and du:

  • The df utility displays information about the total, free, and used memory space of file systems on the disk.
  • The du utility displays the size of files and directories.

With the df -h command, you can see the overall picture: how much free space is left and on which disk partition.

Example output:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           392M  1.5M  391M   1% /run
/dev/vda2        15G   12G  2.4G  84% /
tmpfs           2.0G  1.1M  2.0G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           392M   12K  392M   1% /run/user/0

As a rule, only the partition where the root partition / is mounted needs to be analyzed. In our case, it is /dev/vda2. The example shows:

  • the total size is 15 GB;
  • 12 GB occupied;
  • 2.4 GB free.

In total, 84% of the partition is occupied.

To analyze the occupied space, use the du -sh command, specifying the path to the directory or file. For example, you can view the size of the directory located at /var/www/:

# du -sh /var/www/
659M	/var/www/

To view the size of files and directories inside, you can use the -dX switch, where X is the nesting depth of the view. For example, you can find out the size of files and directories inside /var/www/:

# du -h -d1 /var/www/ | sort
4.0K	/var/www/php-fpm
520K	/var/www/testuser
400K	/var/www/mover
568K	/var/www/php-bin-isp-php84
324K	/var/www/php-bin-isp-php73
4.0K	/var/www/httpd-logs
576K	/var/www/d-suetin
504K	/var/www/php-bin-isp-php83
20K	/var/www/html
472K	/var/www/usertest
3.6M	/var/www/df
340K	/var/www/php-bin-isp-php56
352K	/var/www/php-bin-isp-php74
340K	/var/www/php-bin-isp-php52
64K	/var/www/usr1
53M	/var/www/isimp
419M	/var/www/www-root
200K	/var/www/php-bin
180M	/var/www/importdbtest
128K	/var/www/httpd-cert
72K	/var/www/prefix
659M	/var/www/

To view the size of files and directories in subdirectories, increase the value of the switch, for example -d3.

Each analysis and its results are unique, but there are directories that are most often large:

  • User files of the ispmanager 6 panel at /var/www/USERNAME/
  • Log files of the ispmanager 6 panel at /usr/local/mgr5/var/logs/
  • System log files at /var/log/
  • DBMS binary logs at /var/log/mysql or /var/log/mariadb with the name in the format binlog.00001.