How to Check Disk Space in Linux?
In this Linux tutorial, you will learn how to check disk space in Linux.
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?
- Check Disk Space using df command
- Check Disk Space using du command
- Check Disk Space using graphical tools
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
Best-suited Linux courses for you
Learn Linux with these high-rated online courses
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]
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]
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
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
Check Specific Filesystem Disk Space using df
$df <options> <path>
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
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
Display only the file system and mount point fields:
$df -h –output=source, target
$df -h –output=source,size,used,avail
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>
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>
The output of the du command will show the following information:
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>
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>
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
Or Run the following command in the terminal.
$baobab
In the “Devices & Locations” window, you can easily identify your home directory and any additional disks or storage devices connected to your system.
You can click on any directory or disk to view it in detail
Here we have clicked to view the home directory
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.
- 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
Once installed, launch the application and select the directory you want to analyze.
To launch Filelight you can use command:
$sudo filelight
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.
Use Filelight’s “Scan” option for detailed disk space usage analysis on Linux.
Here we have scanned the Root Folder
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
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