How to Check Disk Space in Linux?

How to Check Disk Space in Linux?

6 mins read893 Views Comment
Updated on Aug 21, 2024 16:59 IST

In this Linux tutorial, you will learn how to check disk space in Linux.

2023_05_Copy-of-Copy-of-Feature-Image-Templates-46.jpg

Disk space management is an important aspect of maintaining a healthy Linux system. Over time, files and programs accumulate, taking up valuable disk space that can slow down your system and cause errors. Therefore, it’s crucial to regularly check your disk space and free up space if necessary. In this article, we’ll discuss how to check disk space in Linux.

Check out free Linux courses

Table of Content

What is Disk Space?

Disk space is the storage capacity available on a computer system’s hard disk drive or another storage device. It is divided into total and available space and is measured in bytes, kilobytes, megabytes, gigabytes, or terabytes. Monitoring disk space usage and regularly deleting unnecessary files is important to free up space and prevent system issues.

Explore Online Linux Courses

How to Install Linux on Windows without Admin Rights?
How to Install Linux on Windows without Admin Rights?
Are you curious about Linux but don’t have admin rights on your Windows computer? Don’t worry, you can still dive into the world of Linux and experience its wonders. In...read more
How to Zip a File in Linux?
How to Zip a File in Linux?
zip command is a Linux utility used to compress and package one or more files or directories into a single ZIP archive. zip command is a Linux utility used to...read more
Using the SED Command in Linux
Using the SED Command in Linux
Discover the versatility of the sed command in Linux for text manipulation in files and streams. Our guide covers basic and advanced features to enhance your productivity. This comprehensive guide...read more
Recommended online courses

Best-suited Linux courses for you

Learn Linux with these high-rated online courses

– / –
200 hours
2 K
20 hours
– / –
3 months
– / –
6 months
Free
8 hours
– / –
40 hours
– / –
3 months
10 K
60 hours
– / –
3 months

Check Disk Space using df command.

The df command stands for disk free, a standard Linux command used to display the disk space usage of the file system. 

The syntax of the df command is as follows:


 
$df [options] [filesystem]
Copy code

The options for the df command are as follows:

  • -h: Human-readable format
  • -T: Show file system type
  • -i: Show inode usage
  • -a: Show all file systems, including system file systems
  • -x: Exclude file systems

To check the disk space usage of all file systems, you can run the df command without any options or arguments. 


 
$df [options] [filesystem]
Copy code
2023_05_image-23.jpg

The output of the df command will show the following information:

  • Filesystem: The name of the file system
  • Type: The file system type
  • Size: The total size of the file system
  • Used: The used space of the file system
  • Available: The available space of the file system
  • Use%: The percentage of the used space

To check disk space in a human-readable way, you must use the “-h” flag.

The “-h” flag is used to display the output in human-readable format, i.e. in units of K, M, G, or T, which makes it easier to understand.


 
$df -h
Copy code
2023_05_image-23.jpg

In this example, the output shows that the file system “/dev/sda3” has a total size of 20 GB, 11 GB of which is used, 7.7 GB is available, and 58% of the disk space is currently being used. 

Please note that when using the “-h” option with certain commands, sizes will be displayed in units of 1024 bytes. If you prefer to see sizes in units of 1000 bytes, you should use the “-H” option instead.


 
$df -H
Copy code
2023_05_image-24.jpg

Check Specific Filesystem Disk Space using df


 
$df <options> <path>
Copy code

The “df -h” command can also be used with the specific file system or partition paths to check their disk space usage. For example, if you want to check the disk space usage of only the “/home” file system, you can run the following command:


 
$df -h /home
Copy code
2023_05_image-26.jpg

The “df -h” command in Linux displays much information about the disk space usage on the system, including the file system name, total size, used space, available space, and mount point. However, sometimes you may only need to see specific fields of information.

To output specific fields of information, you can use the “–output” option followed by a comma-separated list of the fields you want to display. 


 
$df -h –output=source, field1, field2
Copy code

Display only the file system and mount point fields:


 
$df -h –output=source, target
Copy code
2023_05_image-24.jpg

 
$df -h –output=source,size,used,avail
Copy code
2023_05_image-27.jpg

Here are some commonly used field names for the “df” command’s “–output” option, which can be used to display specific information about disk space usage on Linux systems: source, fstype, size, used, avail, pcent, target.

Check Disk Space using du command

The du command stands for disk usage, and it is a standard Linux command that is used to estimate file space usage. The syntax of the du command is as follows:


 
$du <option> <path>
Copy code

The options for the du command are as follows:

  • -h: Human-readable format
  • -s: Summarize the disk usage of each file
  • -c: Display a total disk usage summary
  • -a: Show disk usage of all files, including hidden files

To check the disk space usage of a specific directory or file, you can run the du command with the directory or file path as an argument. 


 
$du <path>
Copy code

The output of the du command will show the following information:

2023_05_image-25.jpg

By default, the sizes are displayed in kilobytes.For example, to check the disk space usage of a specific directory in human-readable format, you can run the following command:


 
$du -h <path>
Copy code
2023_05_image-28.jpg

The du command with the -shc option is used to calculate and display the total disk usage of a directory and its subdirectories in a human-readable format.

Here’s a breakdown of what the -shc options do:

  • The -s option stands for “summarize,”. Depending on the directory size, it will display the total size of a directory and its subdirectories in bytes, kilobytes, megabytes, or gigabytes.
  • The -h option stands for “human-readable,”. It will display the sizes of files and directories in a format that is easier to read and understand.
  • The -c option stands for “total,” and will display the grand total of the disk usage for multiple directories.

You would run the following command to know the total disk usage of directories:


 
$du -shc <path1> <path2>
Copy code
2023_05_image-30.jpg

Check Disk Space Using Graphical Tools

Apart from using the command line, you can also use graphical tools to check disk space usage in Linux. These tools provide a user-friendly interface that can help you easily visualize the disk space usage on your system.

Here are some popular graphical tools that you can use to check disk space usage in Linux:

GNOME Disk Usage Analyzer

GNOME Disk Usage Analyzer is a graphical tool that provides a detailed view of the disk usage of the file system. This is a graphical tool that comes with the GNOME desktop environment. It provides an easy-to-use interface that displays disk usage information as a sunburst chart, allowing you to quickly identify which files or directories are taking up the most space. 

To launch GNOME Disk Usage Analyzer, search for “Disk Usage Analyzer” in your applications menu

2023_05_image-29.jpg

Or Run the following command in the terminal.


 
$baobab
Copy code
2023_05_image-32.jpg

In the “Devices & Locations” window, you can easily identify your home directory and any additional disks or storage devices connected to your system.

2023_05_image-26.jpg

You can click on any directory or disk to view it in detail

Here we have clicked to view the home directory

2023_05_image-29.jpg

The tool provides a user-friendly interface to navigate different folders and visualize how disk space is allocated. 

In addition to the folder structure, an interactive graph is displayed on the side, which provides a comprehensive distribution view of the space occupied by different files and directories. 

2023_05_image-27.jpg
  1. Filelight:

Filelight is a graphical disk usage analyzer tool for Linux systems that visually represents disk space usage. It allows you to easily visualize which directories and files are taking up the most space on your system and can help you identify areas where you can free up space.

To install use the command:


 
$sudo apt-get install filelight
Copy code
2023_05_image-28.jpg

Once installed, launch the application and select the directory you want to analyze.

To launch Filelight you can use command:


 
$sudo filelight
Copy code

When launched, it will automatically scan your system and display the space used for your root partition in a graphical representation of %Used vs %Free.

2023_05_image-25.jpg

Use Filelight’s “Scan” option for detailed disk space usage analysis on Linux.

Here we have scanned the Root Folder

2023_05_image-31.jpg

The tool displays the results in an easy-to-read graphical representation and provides a list view for sorting the data. This feature helps you identify which directories and files take up the most space on your system, allowing you to free up space as needed.

Conclusion

Monitoring disk space usage is crucial for any Linux system administrator to ensure that the system runs smoothly without any disruptions due to low disk space. In this article, we explored several methods to check disk space usage on a Linux system, including command line tools such as df and du and graphical tools such as GNOME Disk Usage Analyzer and Filelight.

Contributed By: Anish Lohiya

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio