How To Check Disk Space In Linux?

While using a Linux system on a desktop, laptop, or server the disk space is important to monitor. The disk is used to store different types of data like files, database servers, codes, libraries, executables, etc. Linux provides different commands and tools in order to check disk space from a different point of view. Mainly the df and du commands are used to check disk space like free, used disk space, etc. Keep in mind that reading some directories and getting disk usage information may require root privileges were the sudo command can be used.

Check Disk Space with df Command

By using the df command the disk usage about every partition mounted on a Linux system can be listed like below. There will be no parameter or option.

$ df 
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             1972944        0   1972944   0% /dev
tmpfs             400228     1808    398420   1% /run
/dev/sda5      102168536 11925140  85010500  13% /
tmpfs            2001120        0   2001120   0% /dev/shm
tmpfs               5120        0      5120   0% /run/lock
tmpfs            2001120        0   2001120   0% /sys/fs/cgroup
/dev/loop0         56320    56320         0 100% /snap/core18/1880
/dev/loop2        261760   261760         0 100% /snap/gnome-3-34-1804/36
/dev/loop1         56704    56704         0 100% /snap/core18/1885
/dev/loop3        166784   166784         0 100% /snap/gnome-3-28-1804/145
/dev/loop4        223232   223232         0 100% /snap/gnome-3-34-1804/60
/dev/loop5         63616    63616         0 100% /snap/gtk-common-themes/1506
/dev/loop6          4224     4224         0 100% /snap/notepad-plus-plus/238
/dev/loop7         44288    44288         0 100% /snap/snap-store/415
/dev/loop9         31744    31744         0 100% /snap/snapd/9607
/dev/loop10        51968    51968         0 100% /snap/snap-store/481

From the df command output we can see that following information is provided.

  • Filesystem is the partition or disk which is mounted as file system. Filesystem can be a partition or loop device.
  • 1K-blocks is the count or 1 kilobyte blocks which is actually not a human readable format like megabyte or gigabyte.
  • Used is the count of used 1K-blocks.
  • Available is the free or available 1K-blocks.
  • Use% display the percentage of the used disk space for specified partition or file system.
  • Mounted on provides the mount point of the given partition of file system.

Display df Command Help

Before diving deep about listing disk usage of the Linux system with the df command we will display help information about the df command. As an old and popular command, df command provides a lot of options and features which can be listed with the help information completely. Even te --help option provides some helpful information please refer to the man page like below.

$ df --help

$ man df
Display df Command Help

Display Usage in Megabytes and Gigabytes

Even the df command provides the free, used size of the disk, partition, and file system information it will be printed as 1K-block. But this is not a human-readable format. You can use the -h which is a short form of –human-readable format in order to list sizes in Gigabytes (GB), Megabytes (MB).

$ df -h
Display Usage in Megabytes and Gigabytes

In order to display all sizes in Megabyte (MB) format use the -m option like below.

$ df -h

Display Usage for /home Directory

/home directory is used to store user files for their private usage area. In multiple user systems users store their data, files, folders, etc. in their home directory located /home. . We will provide the -T option which will list the /home directory summary usage.

$ df -hT /home

Display Specific Partition or File System Disk Usage

By default the df command will list all files systems and partitions disk usage. Especially in modern Linux systems it can produce a lot of unnecassary output because of pseudo file systems. We can list a specific partition or file system disk usage by specifying the path or partition like below. In the following exmaple we will list disk usage only for the / file systems.

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        98G   12G   82G  13% /

Display Specified File System Partitions

Linux supports different file systems like ext2, ext3, ext4, btrfs, xfs etc. The current file systems and partitions can be listed according to their file system type with the -t option which is a short form of the type. In the following example, we will list the ext4 file system.

$ df -t ext4

Check Disk Space Usage For Specific Directory with du Command

du is a command to estimate file space usage for Linux. The du command summarize disk usage of the set of files, recursively for directories. Help information about the du command can be listed with the --help option like below.

$ du --help
Check Disk Space Usage For Specific Directory with du Command

The du command can be used with the -h option in order to list output in human-readable format by printing sizes as Kilobyte (KB), Megabyte (MB), Gigabyte (GB).

$ du -h /home/ismail
Check Disk Space Usage For Specific Directory with du Command

From the output we can see that the directories are listed with the total sizes as Kilobyte. The kilobyte is expressed with the K in short.

Leave a Comment