Useful Examples & Commands for Harddisk Management (Disk Usage)

Last updated:

Here are some commands that can help you view the state of your hard disk:

You should probably run these commands as root (or using sudo)

System Disk Usage by Directory

To see where your disk space has gone

$ sudo du -h / | sort -h

Example output (some lines ignored)

14G  /home/johndoe/Downloads
15G  /home/johndoe
16G  /home
35G  /var/lib 
40G  /var
99G  /

Disk Usage by Partition

$ sudo df -h

Example output

Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu1264-root  28G    17G   11G  62% /
udev                         988M  4.0K  988M   1% /dev
tmpfs                        199M  276K  199M   1% /run
none                         5.0M     0  5.0M   0% /run/lock
none                         995M     0  995M   0% /run/shm
/dev/sda1                    228M   71M  145M  33% /boot

Size of each file and directory under /path/to/directory/

$ sudo du -h /home/johndoe/ | sort -h

Example output (some lines ignored)

27M  /home/johndoe/Downloads/yii_13
35M  /home/johndoe/proj.git/objects/pack
44M  /home/johndoe/proj.git/objects
45M  /home/johndoe/proj.git
74M  /home/johndoe/Downloads/elasticsearch-1.2.1
204M /home/johndoe/Downloads
464M /home/johndoe/dump.sql
667M /home/johndoe/dump2.sql
1.4G /home/johndoe/

Size of each directory under /path/to/directory

This is the same as before but only directories, not files, are shown.

Note that this is a slightly modified version of the first example, where you specify a directory rather than the whole disk.

$ sudo du -h /home/johndoe/ | sort -h

Example output (some lines ignored)

27M  /home/johndoe/Downloads/yii_13
35M  /home/johndoe/3bsa.git/objects/pack
44M  /home/johndoe/3bsa.git/objects
45M  /home/johndoe/3bsa.git
74M  /home/johndoe/Downloads/elasticsearch-1.2.1
204M /home/johndoe/Downloads
1.4G /home/johndoe/

References

Dialogue & Discussion