Where disk space has gone?

Submitted by christophe on Mon, 10/04/2017 - 13:52

On the track of the elephants

The df -h command shows the remaining space in human readable format.
If your disk is almost full (Use% column in the df -h result), you should go for the du command, see below.

Also, it can be useful to check the free inodes with df -i, in this case, elephants could be thousands of mice (small files). This is misleading because the df -h command can show that there is plenty of space left but the issue could just be too many inodes, often caused by temporary files, maildrop, ... .
If the IUse% column in the df -i result tends to be close to 100%, this is probably the problem.
Then, you can print the list of every directory, sorted by the less files to the more files per directory (largest number of files will be at the bottom).

find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

If your problem is really elephants, then the du command can be used to identify the heavy weighted directories.

Sort by weight on the first level of a directory (change --max-depth value to have more levels).

du --si --max-depth=1 <dir>| sort -n -r

Or just identify the directories that contains G(igabytes) as output of the du command

du -h <dir> | grep '[0-9\.]\+G'

Then we can refine per (M)egabytes

du -h <dir> | grep '[0-9\.]\+M'

Get the sizes of MySQL tables

If your /var/lib/mysql/ is crowded, this query orders by size the tables in each database.

     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;


Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.