A good[ish] website

Web development blog, loads of UI and JavaScript topics

Find out what takes space on the hard drive, in a Linux/Unix machine

Filed under: Server— Tagged with: shell, database

I was just struggling with a machine that was totally out of space. Here’s some ways to figure out what is hogging the storage real estate.

Find out the system capacity and available disc space

Use the df "disk filesystem" (or "disk free") command to see how much there is free space on the disc(s):

$ df -H
Filesystem      Size  Used Avail Use% Mounted on
udev            1.1G  8.2k  1.1G   1% /dev
tmpfs           210M  418k  210M   1% /run
/dev/vda1        32G   21G  9.0G  71% /

This will show all the mounted filesystems. Get usage of individual filesystem by referring it by name:

$ df -H /dev/vda1

Find out the size of a file

The ls command coupled with "the human readable", "list", and "all" flags is great for gauging file sizes in a directory:

$ ls -lah

That’ll show hidden files also.

The du (disk use) command

The "disk use" command shows the size of a file:

$ du -h

Find out size of a directory

Couple the du command with the "summarize" -s, --summarize flag and it shows the size of a directory:

$ du -sh /var/www
8.9G    /var/www
-s, --summarize
Display only a total for each argument.
-h, --human-readable
Print sizes in human readable format (e.g., 1K 234M 2G).

The next one lists the sizes of the 10 largest directories in the current working directory, in human readable form:

$ cd /var/www
$ du -hsx * | sort -rh | head -10


Find packages that take a lot of space

In Debian systems you can use the aptitude command to sort by installsize, and then pipe it to the tail command to get a reasonable amount of results. This churns out the packages in ascending order:

$ aptitude search "~i" --display-format "%p %I" --sort installsize | tail -10
linux-headers-3.8.0-29                    60.1 MB
libwireshark3                             62.9 MB
linux-headers-3.13.0-51                   63.4 MB
linux-headers-3.13.0-161                  63.6 MB
libwireshark11                            83.9 MB
linux-firmware                             127 MB
linux-image-extra-3.13.0-51-generic       152 MB
linux-image-extra-3.13.0-161-generic      155 MB
linux-image-3.8.0-29-generic              176 MB
mongodb-org-tools                         238 MB

Tweak the number in tail to get more results.

Check for MySQL databases

Maybe there’s bloated database that gulps lion’s share of space, log in to MySQL prompt to check that:

$ mysql -u root -p

See if you have too many databases, or something like that:


Or get a database size in human readable form:

SELECT table_schema AS "db_name", SUM(data_length + index_length) / 1024 / 1024 / 1024 AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema

I’ve got a post with simple MySQL operations, if you’re interested.

Check the size of logs

Just to be sure that logs haven’t bloated out of control for some reason, the /var/log can be checked:

$ du -sh /var/log
629M    /var/log

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!