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.
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
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 "disk use" command shows the size of a file:
$ du -h archive.zip 800M archive.zip
du command with the "summarize"
-s, --summarize flag and it shows the size of a directory:
$ du -sh /var/www 8.9G /var/www
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
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.
Maybe there’s bloated database that gulps lions share of space, log in to MySQL promp 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.
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. Tweet me @hiljaa if you want to make a correction etc.