How to Check Disk Space?

There are two useful commands for checking disk space in a Linux-based system, which is df (disk free) and du (disk usage).

1. df#

The df command stands for disk free, and it shows you the amount of space taken up by different drives. By default, df displays values in 1-kilobyte blocks.

image

Display Usage in Megabytes and Gigabytes

You can display disk usage in a more human-readable format by adding the -h option:

$ df -h

This displays the size in kilobytes (K), megabytes (M), and gigabytes (G).

Understanding the Output:

The df command lists several columns:

Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          492676       0    492676   0% /dev
tmpfs             503444       0    503444   0% /dev/shm
tmpfs             503444     432    503012   1% /run
tmpfs             503444       0    503444   0% /sys/fs/cgroup
/dev/xvda1       8376300 1546728   6829572  19% /

image

The columns should be self-explanatory:

Filesystem – This is the name of each particular drive. This includes physical hard drives, logical (partitioned) drives, and virtual or temporary drives.
1K-blocks – The size of the filesystem.
Used – Amount of space used on each filesystem.
Available – The amount of unused (free) space on the filesystem.
Use% – Shows the percent of the disk used.
Mounted on – This is the directory where the file system is located. This is also sometimes called a mount point.

The list of filesystems includes your physical hard drive, as well as virtual hard drives:

/dev/xvda1 – This is your physical hard drive. It may be listed as /xvda1, /xvda0, or you may even have more than one. /dev stands for device.
devtmpfs – This is a virtual directory for the /dev directory. This is part of the Linux operating system.
tmpfs – You may have several of these. These are used by /run and other Linux processes as temporary filesystems for running the operating system. For example, the tmpfs /run/lock is used to create lockfiles. These are the files that prevent multiple users from changing the same file at the same time.

Display a Specific File System

The df command can be used to display a specific file system:

$ df -h /dev/xvda1
$ df -h /

This displays the usage on your primary hard drive. Use the mount point (in the Mounted on column) to specify the drive you want to check.

Display File Systems by Type

To list all file systems by type, use the command:

$ df -ht ext4

This lists drives with the ext4 type, in human-readable format.

Display Size in 1000 Instead of 1024

You can display disk usage in units of 1000 instead of 1024:

$ df -H

This can address a point of confusion in storage technology. Hard drive manufacturers sell hard drives in sizes based on 1000 bytes = 1 kilobyte.

However, operating systems divide that space up so that 1024 bytes = 1 kilobyte. Because of this, a 1000-gigabyte hard drive ends up with roughly 930 gigabytes of usable storage.

2. du#

The du command displays disk usage. This tool can display disk usage for individual directories in Linux, giving you a finer-grained view of your disk usage. Here’s how you use it:

$ du

image

Like the df command, you can make du human-readable:

$ du -h

It displays a list of the contents of the current directory, and how much space they are using. You can simplify the display with the -s option:

$ du -hs

image

This shows how much space the current directory uses. You can also specify the file/directory name after the options, to check the space on the particular file/directory.

comments powered by Disqus