Linux Commands for checking how much space is left on disk

1. Overview

In the Linux world, monitoring system resources is an important task for power users and system administrators. One of the critical resources that often needs to be checked is disk space. Knowing how to effectively check and manage disk space can be the difference between a smoothly running system and one plagued with issues.

In this tutorial, we’ll discuss all possible practices of Linux commands for checking disk space.

2. Using the df Command

The df or disk free is a fundamental command utilized to visualize the available disk space on filesystem partitions. Moreover, we can use the df command to check the available and used disk space on the system. The general syntax of the command is simply df.

Let’s look at its usage in a Linux terminal:

In the above output, we see the Filesystem, 1K-blocks, Used, Available, Use%, and Mounted on columns.

We can display the numeric regarding disk space available as well as used on all mounted filesystems such as tmpfs, etc. Furthermore, the df command can also be used to see the disk usage of directories and subdirectories as well.

However, we can use the df -h command to make sure that the information is in readable format. Here, the -h option stands for human-readable, which displays the sizes in KB, MB, and GB as well:

In the above command, we can see the Size, Used, and Avail columns that show total, used, and available space on the system. Furthermore, we can also visualize Use% and Mounted on columns that represent the disk usage in percentage and mount point, respectively. For example, the /dev/sda2 filesystem occupies 11GB out of 25GB.

To check the inode usage on the Linux terminal, we can use the df -i command. It gives information about the number of inodes being used by the Linux system:

In this output, we can see that inodes store information about files and directories, containing number of inodes, used, free inodes, along with their corresponding percentages.

3. Using the du Command

The du disk usage command is utilized to estimate the file space usage of a given directory or file. By default, du displays the usage of disk for a directory as well as its subdirectories in kilobytes.

Now, we learn the du command in the Linux terminal:

To get a more comprehensible output, we run the du -h command, which is also like to df -h command:

Here, we see the disk usage information more in a human-readable layout.

To check the disk usage of a specific file as well as a directory, such as “Downloads” and suppress the rest, we run the du -s command:

4. Using the lsblk Command

The lsblk command lists the information regarding specified as well as all available block devices. It reads and extracts the udev dbas well as the sysfs filesystemfor collecting information.

In addition, we can utilize the lsblk command to check the disk usage space on our system:

In the above output, we see all block devices such as loop0, loop1, etc. along with their associated disk space.

5. Using the ls Command

To check disk space in Unix-like operating systems, we can also use the ls command. However, it lists files and directories rather than disk usage.

Now, we learn the ls command in the Linux terminal:

In the above output, the ls command lists directory information. However, it does not show the actual space of the directory as well as the files inside it. For example, a Downloads directory takes up 4096 bytes. This number represents the space the directory’s index occupies on the disk.

However, the Downloadsdirectory contains two large files of total size 12-megabyte which we can see via the ls -lh options for human readable format:

6. Using the find Command

In Linux, the find command is useful for locating files that meet the specified conditions. Moreover, we can also combine it with other commands through a pipe operator to manage disk space.

For instance, let’s run the find command in the Linux terminal:

In the above output, find command search for files throughout the entire filesystem that are larger than 50 megabytes. Furthermore, / denotes the root directory for the starting point for the search. The -type f option is utilized to find only regular files, not including folders or other kinds of files.

To list detailed information about each file in a directory hierarchy with human-readable file sizes,use the find . -type f -exec ls -lh {} \; command as below:

In this command, find searches all files in the current directory. Then, the ls -lh command lists the file details in a readable format. Furthermore, {} stands for each file that is discovered, and; marks the spot where the command finishes.

As a result, the output shows the permissions (who can access each file), links, owner (who owns it), group (which group it belongs to), size, modification date (when it was last changed), and filename for each file found.

Conclusion

In this article, we’ve learned all possible methods for checking disk space in Linux such as the df du, ls, lsblk, and find command.

Naturally, the df command is a great choice for checking disk space because of its efficiency and ease of use. Meanwhile, the du command estimates file space usage for more detailed information. Furthermore, we can also use ls, lsblk and findcommands with different operations to get the summary of available as well as used disk space on the system.

Ultimately, we can employ any of these efficient methods depending on the particular needs for checking disk space.

Scroll to Top