Javatpoint Logo
Javatpoint Logo

Linux Check Disk Space

It is an essential step to manage disk space over a Linux server. For example, various applications of package manager inform us how much disk space would be needed for the installation process. We should understand how much space our system has available for the data to be meaningful.

In this topic, we will understand how to apply the df command for checking the disk space on Linux and also the du command for displaying the disk space usage of the file system.

Prerequisites

  • The Linux-based system
  • A command line or terminal window
  • A user account with root or sudo privileges

Check disk space with the df command

Using the df command, we can check our disk space by opening the terminal window and simply typing the following command:


Linux Check Disk Space

This command is short for disk free. It shows us the space amount taken up by distinct drives. The df command by default shows values in the 1-kilobyte blocks.

Check Disk Space in Gigabytes and Megabytes

We can show the usage of the disk in human-readable format by including the following option with the df command:


Linux Check Disk Space

After using the above command, the size will display in gigabytes, megabytes, and kilobytes.

Knowing the Format of the Output

The df command will list various columns which are listed and explained below:

  • Filesystem: It is the name of all specific drives. It includes logical drives, physical hard drives, and temporary or virtual drives.
  • Size: It is the size of the file system.
  • Used: It is the space amount used on all file systems.
  • Avail: It is the unused space amount on all file systems.
  • Use%: It displays the percentage of disk usage.
  • Mounted on: It is the directory in which the file system is positioned. Also, it is sometimes known as the mount point.

The filesystems list contains our virtual hard drives and physical hard drivers as well:

  • /dev/sda2: It is our physical hard drive. This entry might be listed like the /sda1/sda0 or we might even have multiple. It is short for the device.
  • /udev: It is a virtual directory for another directory that is /dev. It is a part of the Linux OS.
  • tmpfs: We might have many of these. These types of entries are utilized by the /run directory and the other processes of Linux as various temporary filesystems to run the OS.

For example, the tmpfs/run/lock directory is used for creating lock files. The lock files are the files that restrict more than one user from modifying a similar file at a time.

Display a Particular File System

The df command could be used for displaying a particular file system:


Linux Check Disk Space

Also, we can add a backslash:


Linux Check Disk Space

It will show the usage on our main hard drive. We can apply the mount point (inside the Mounted on entry) for specifying the drive we wish to check.

Note: The df command targets a complete filesystem only. Even when we describe a single directory, the df command will know the space of the entire drive.

Display the File Systems by Their Type

We can use the following command for listing every file system by its type:


Linux Check Disk Space

It will list the drives along with the type, i.e., ext4 in a more human-readable style.

Show Size in 1000 Rather Than 1024

We can show the usage of the disk in 1000 units rather than 1024:


Linux Check Disk Space

It can address the confusion point inside the storage mechanism. Many manufacturers of hard drives sell their hard drives in distinct sizes based on the 1000 bytes which are equal to 1 kilobyte.

Although, operating systems categorize that space up, where:

1 kilobyte = 1024 bytes

The hard drive of 1000 gigabytes ends up with 930 gigabytes of accessible storage roughly due to this reason.

Check Disk Space Using the du Command

In Linux, the du command can also be used for displaying the usage of the disk. This tool can show the usage of the disk for a single directory in Linux, providing us a finer-grained perspective of our disk usage. We can use it for displaying the space amount utilized by our current directory:


Linux Check Disk Space

We can enable the du command to be more human-readable just like the df command:


Linux Check Disk Space

It will show how much disk space is consumed by the contents of our current directory and the list of various contents of the current directory.

We can also clarify the display by using the -s option:


Linux Check Disk Space

It will show how much space is consumed by our current directory.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA