Linux commands to check disk space utilization

Sanju Mathew
4 min readOct 5, 2021

--

In this article, let’s visit some Linux built-in utilities for keeping track of disk utilization.

· df command

· du command

· ls -al command

· fdisk -l command

· stat command

df command:

The df (disk filesystems, sometimes called disk free) command displays the amount of disk space available on a file system, if no filename is given then the space available on all currently mounted file systems is displayed.

Basic syntax of df command: df [options] [devices]

By default, df displays the values in 1-Kilobyte blocks.

Each line has six fields or columns:

1. Filesystem: Name of the filesystem

2. 1K-Blocks: Number of 1K blocks available on the filesystem

3. Used: Number of 1K blocks used on the filesystem

4. Available: Number of unused 1K blocks on the filesystem

5. Use%: Space usage on the filesystem displayed as a percentage

6. Mounted On: Mount point of the filesystem

Commonly used options with the df command are:

df -H: The -H option displays disk space utilization information in kilobytes (K), megabytes (M) and gigabytes (G) and therefore provides better readability.

df -m: Shows the output in one-megabyte block size. Similarly, it can also be shown in a one-gigabyte block by using -g option.

df -i: Displays disk information in numbers of inodes. An inode is used by Linux filesystems to describe files and to store metadata about the files.

df -T: Provides the disk space information based on the type of each filesystem such as ext4, btrfs, ext2, nfs4, fuse, cgroup and cputset.

df -x: Shows information of all excluding the type of filesystem selected in the command. In the example, df -x tmpfs command lists all but excludes tmpfs filesystems.

df — output=field1,field2: Disk space information is displayed according to the fields selected along with the — output option.

The table below shows the valid field names for the display names:

df — help: Displays a brief help message with the various options that can be used with df command.

man df: Provides the man page for the df command and its a great way to start learning about any built-in utility in Linux.

du command:

The du (disk usage) command is useful to find out the directories and files that consume large amounts of space on the disk.

The basic syntax of du command:

du

du [options] [directories or files]

Commonly used options with the du command are:

du: Displays the names and space consumption of each directory including all subdirectories in the directory tree. The first column displays file size in kilobytes and the second column is the name of the filesystem.

du -h: Displays the information in human-readable format displaying the file size in kilobytes(K), megabytes(M) or gigabytes(G).

du [directory or file]: Displays disk space usage information about the specific directory and in this example its shows disk space usage in the /etc/ folder.

du -sh /etc/: This shows the total disk space taken up by the directory tree and to suppress subdirectories.

du -ah /etc/: This option is used to view all files and not just directories. Adding -h option will provide more readability and display disk space information in a better format.

du — help

man du

These commands provide more information on the different options that can be used along with the du command.

ls -al command:

The ls -al command displays the entire contents of a directory along with its size.

fdisk -l command:

The fdisk -l command displays the disk size along with disk partitioning details.

stat command:

The stat <file/directory> command displays the size and other stats of a file/directory

These are the most commonly used Linux built-in utilities to easily find out how much hard disk space is in use, and it also helps to identify where most of the space is being utilized. This knowledge can help to make an informed decision about adding more space or moving some data to another storage device or even deleting redundant files/directories.

--

--