If you're new to the Linux environment, it's common to feel puzzled by certain commands, especially when they serve similar purposes. One such confusion arises between the df and du commands, both of which are used for disk space analysis. Don't worry, you're not alone! Understanding df and du commands and their distinct purposes is key to effectively managing your disk space in Linux. In this beginner-friendly guide, we will demystify the df and du commands, helping you gain clarity on their functionalities and how they contribute to analyzing disk space in Linux. By the end of this article, you'll feel confident in distinguishing between these commands and utilizing them to make informed decisions about your disk space management.
Table of Contents
Understanding df and du Commands in Linux
The df and du commands are both used for disk space analysis in Linux, but they serve different purposes. First, we will discuss about df command.
1. df Command
The df command stands for "disk free" and is used to display information about file system disk space usage. It provides an overview of available, used, and total disk space on mounted file systems. It helps you understand how much space is used and how much is available on each partition or file system.
Example:
$ df -h
Explanation:
The command displays disk space usage in a human-readable format (-h), providing information about file systems, their total size, used space, available space, and utilization percentage.
1.1. df Command Examples
Here are some examples of using the df command along with their explanations:
1. Basic Disk Space Usage:
$ df
Sample Output:
Filesystem 1K-blocks Used Available Use% Mounted on udev 16191444 0 16191444 0% /dev tmpfs 3248044 1936 3246108 1% /run /dev/nvme0n1p2 478096136 186495704 267241008 42% / tmpfs 16240220 25348 16214872 1% /dev/shm tmpfs 5120 4 5116 1% /run/lock /dev/nvme0n1p1 523248 3484 519764 1% /boot/efi /dev/sda1 976698752 389951104 586747648 40% /media/ostechnix/SK_WD_SSD /dev/fuse 131072 20 131052 1% /etc/pve tmpfs 3248044 1644 3246400 1% /run/user/1000
Explanation:
Running df without any options displays disk space usage for all mounted file systems. It shows information such as file system, total size, used space, available space, and the mount point.
2. Human-Readable Output:
$ df -h
Sample Output:
Filesystem Size Used Avail Use% Mounted on udev 16G 0 16G 0% /dev tmpfs 3.1G 1.9M 3.1G 1% /run /dev/nvme0n1p2 456G 178G 255G 42% / tmpfs 16G 25M 16G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock /dev/nvme0n1p1 511M 3.5M 508M 1% /boot/efi /dev/sda1 932G 372G 560G 40% /media/ostechnix/SK_WD_SSD /dev/fuse 128M 20K 128M 1% /etc/pve tmpfs 3.1G 1.7M 3.1G 1% /run/user/1000
Explanation:
Adding the -h option makes the output human-readable, displaying sizes in a more understandable format (e.g., KB, MB, GB).
3. Specific File System:
$ df /dev/sda1
Sample Output:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 976698752 389951104 586747648 40% /media/ostechnix/SK_WD_SSD
Explanation:
Specifying a file system, such as /dev/sda1, shows disk space usage specifically for that file system.
4. Multiple File Systems:
$ df /dev/sda1 /dev/sdb1
Explanation:
You can provide multiple file system paths as arguments to the df command to see the disk space usage for each of them.
5. Inode Usage:
$ df -i
Sample Output:
Filesystem Inodes IUsed IFree IUse% Mounted on udev 4047861 617 4047244 1% /dev tmpfs 4060055 1122 4058933 1% /run /dev/nvme0n1p2 30433280 1402561 29030719 5% / tmpfs 4060055 61 4059994 1% /dev/shm tmpfs 4060055 14 4060041 1% /run/lock /dev/nvme0n1p1 0 0 0 - /boot/efi /dev/sda1 0 0 0 - /media/ostechnix/SK_WD_SSD /dev/fuse 262144 37 262107 1% /etc/pve tmpfs 812011 104 811907 1% /run/user/1000
Explanation:
Using the -i option displays the inode usage, which shows information about the number of used and available inodes on each file system.
6. Display File System Type:
$ df -T
Sample Output:
Filesystem <strong><mark>Type</mark></strong> 1K-blocks Used Available Use% Mounted on udev <strong><mark>devtmpfs</mark></strong> 16191444 0 16191444 0% /dev tmpfs <strong><mark>tmpfs</mark></strong> 3248044 1936 3246108 1% /run /dev/nvme0n1p2 <strong><mark>ext4</mark></strong> 478096136 186495792 267240920 42% / tmpfs <strong><mark>tmpfs</mark></strong> 16240220 25348 16214872 1% /dev/shm tmpfs <strong><mark>tmpfs</mark></strong> 5120 4 5116 1% /run/lock /dev/nvme0n1p1 <strong><mark>vfat</mark></strong> 523248 3484 519764 1% /boot/efi /dev/sda1 <strong><mark>exfat</mark></strong> 976698752 389951104 586747648 40% /media/ostechnix/SK_WD_SSD /dev/fuse <strong><mark>fuse</mark></strong> 131072 20 131052 1% /etc/pve tmpfs <strong><mark>tmpfs</mark></strong> 3248044 1644 3246400 1% /run/user/1000
Explanation:
Adding the -T option shows the file system type along with disk space usage information.
7. Exclude Pseudo File Systems:
$ df -x tmpfs -x devtmpfs
Sample Output:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/nvme0n1p2 478096136 186495884 267240828 42% / /dev/nvme0n1p1 523248 3484 519764 1% /boot/efi /dev/sda1 976698752 389951104 586747648 40% /media/ostechnix/SK_WD_SSD /dev/fuse 131072 20 131052 1% /etc/pve
Explanation:
The -x option followed by one or more file system types excludes them from the output. In this example, we exclude the tmpfs and devtmpfs file systems.
8. Display File System inodes and Blocks:
$ df -i -B M
Sample Output:
Filesystem Inodes IUsed IFree IUse% Mounted on udev 4047861 617 4047244 1% /dev tmpfs 4060055 1122 4058933 1% /run /dev/nvme0n1p2 30433280 1402573 29030707 5% / tmpfs 4060055 61 4059994 1% /dev/shm tmpfs 4060055 14 4060041 1% /run/lock /dev/nvme0n1p1 0 0 0 - /boot/efi /dev/sda1 0 0 0 - /media/ostechnix/SK_WD_SSD /dev/fuse 262144 37 262107 1% /etc/pve tmpfs 812011 104 811907 1% /run/user/1000
Explanation:
Combining the -i option with the -B option specifies the block size and displays both the inode and block usage.
9. Include File System Type:
$ df -t ext4
Sample Output:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/nvme0n1p2 478096136 186495964 267240748 42% /
Explanation:
The -t option followed by a file system type shows disk space usage only for that specific file system type. In this example, it displays usage for the ext4 file system.
10. Show Disk Space in 1K Blocks:
$ df -k
Sample Output:
Filesystem 1K-blocks Used Available Use% Mounted on udev 16191444 0 16191444 0% /dev tmpfs 3248044 1936 3246108 1% /run /dev/nvme0n1p2 478096136 186496000 267240712 42% / tmpfs 16240220 25348 16214872 1% /dev/shm tmpfs 5120 4 5116 1% /run/lock /dev/nvme0n1p1 523248 3484 519764 1% /boot/efi /dev/sda1 976698752 389951104 586747648 40% /media/ostechnix/SK_WD_SSD /dev/fuse 131072 20 131052 1% /etc/pve tmpfs 3248044 1644 3246400 1% /run/user/1000
Explanation:
Using the -k option shows disk space usage in 1K blocks.
These examples illustrate various scenarios where the df command can be used to obtain disk space usage information in Linux.
Now let us learn about du command.
2. du Command
The du command stands for "disk usage" and is used to estimate file and directory disk usage. It helps you determine the space consumed by individual directories or files, making it useful for identifying space-hogging directories or large files.
Example:
$ du -sh /path/to/directory
Explanation:
The command calculates the total disk usage (-s) of the specified directory and its subdirectories in a human-readable format (-h). It provides the sum of disk usage by displaying the total size (-h).
2.1. du Command Examples
Here are some examples of using the du command along with their explanations:
1. Basic Disk Usage for a Directory:
$ du dir1
Sample Output:
4400 dir1/dir2 50480 dir1
Explanation:
Running du followed by the path to a directory displays the disk usage of that directory (In this case, dir1) and its subdirectories.
2. Human-Readable Output:
$ du -h dir1
Sample Output:
4.3M dir1/dir2 50M dir1
Explanation:
Adding the -h option makes the output human-readable, displaying sizes in a more understandable format (e.g., KB, MB, GB).
3. Total Disk Usage of a Directory:
$ du -sh dir1
Sample Output:
50M dir1
Explanation:
The -s option provides a summary of the total disk usage of the specified directory without displaying individual subdirectory sizes. The -h option makes the output human-readable.
4. Disk Usage of All Files and Directories in Current Directory:
$ du -h *
Sample Output:
4.3M dir2 5.8M document.pdf 116K image.jpeg 4.0K New Empty File 40M video.webm
Explanation:
Running du with * displays the disk usage of all files and directories in the current directory.
5. Disk Usage Sorted by Size:
$ du -sh * | sort -hr
Sample Output:
40M video.webm 5.8M document.pdf 4.3M dir2 116K image.jpeg 4.0K New Empty File
Explanation:
By piping the output of du to sort command, you can sort the disk usage in descending order (-r flag) to see the largest files or directories at the top. The -h option makes the output human-readable.
6. Disk Usage of Individual Files:
$ du -h dir1/document.pdf
Sample Output:
5.8M dir1/document.pdf
Explanation:
You can use du to get the disk usage of individual files by providing the path to the file as an argument.
7. Disk Usage Excluding Directories:
$ du -d 1 -h --exclude=dir2 dir1
Sample Output:
45M dir1
Explanation:
The --exclude option allows you to exclude specific directories from the disk usage calculation. In this example, the disk usage is calculated for the dir1 directory (i.e. parent directory), excluding the specified directory i.e. dir2. Here, the -d option specifies the depth or level of the directory hierarchy to be displayed. In this case, -d 1 limits the output to only the current directory and its immediate subdirectories.
8. Disk Usage of Multiple Directories:
$ du -h dir1/ Downloads/
Explanation:
You can provide multiple directory paths as arguments to the du command to get the disk usage of each directory separately.
9. Disk Usage of Current Directory and Subdirectories:
$ du -h .
Explanation:
Using . as the argument for du displays the disk usage of the current directory and all its subdirectories.
10. Disk Usage of the Largest Directories:
$ du -h --max-depth=1 dir1 | sort -hr
Sample Output:
50M dir1 4.3M dir1/dir2
Explanation:
By specifying the --max-depth option, you can limit the depth of the disk usage calculation. It is equivalent to -d option. In this example, it displays the disk usage of the top-level directories within the specified directory, sorted in descending order.
These examples demonstrate different ways to use the du command to analyze disk usage in Linux.
Now that we have explored the df and du commands, including their definitions and examples. I hope you have obtained a fundamental understanding of these two disk space analysis tools. With this knowledge in place, we can now shift our focus towards examining the difference between df and du with an example.
Difference between df and du Commands
- Purpose: df shows the overall disk space usage for mounted file systems, providing an overview of available and used space on each partition. On the other hand, du focuses on estimating the disk usage of individual directories or files, helping you identify space-consuming elements.
- Scope: df covers the entire file system, displaying disk space utilization for each mounted file system, while du allows you to drill down and analyze disk usage at the directory or file level.
- Usage: df is commonly used to monitor disk space availability and identify potential storage constraints, while du is helpful for identifying directories or files that contribute significantly to disk space usage.
Example Scenario:
Suppose you have a file system with multiple partitions: /dev/sda1 mounted on / and /dev/sda2 mounted on /home. Running df -h will provide information about the disk space utilization for these mounted partitions. In contrast, running du -sh /home will estimate the disk usage of the /home directory and its subdirectories, helping you identify space-consuming directories within /home.
In summary, df provides an overview of disk space usage at the file system level, while du helps estimate disk usage at the directory or file level. By using both commands appropriately, you can gain insights into disk space utilization and effectively manage your storage resources in Linux.
Frequently Asked Questions
Here's the FAQ about df and du commands.
Q: What is the df command used for?A: The df command in Linux is used to display information about file system disk space usage. It provides details such as total, used, and available space on mounted file systems.
Q: What is the du command used for?A: The du command in Linux is used to estimate disk usage for directories and files. It helps identify the space consumed by individual directories or files.
Q: How do the df and du commands differ in their purpose?A: The df command provides an overview of file system disk space usage, giving information about total, used, and available space. On the other hand, the du command estimates disk usage for directories and files, allowing for a more detailed analysis at the directory and file level.
Q: Can the df and du commands be used together?A: Yes, the df and du commands serve different purposes and can be used in conjunction to gain comprehensive insights into disk space utilization. While df provides a high-level view, du allows for a granular examination of disk usage at the directory and file level.
Q: How can I use the df command to check disk space usage for a specific file system?A: You can use the df command followed by the path to the specific file system to view its disk space usage. For example: df /dev/sda1.
Q: How can I use the du command to check disk usage for a specific directory?A: To check the disk usage of a specific directory, use the du command followed by the path to the directory. For example: du /path/to/directory
Q: Can I exclude specific directories or files from disk usage calculations?A: Yes, both the df and du commands provide options to exclude specific directories or files from the disk usage calculations. For example, with du, you can use the --exclude option followed by the directory or file name to exclude it from the calculation.
Q: Are there any additional options available for df and du commands?A: Yes, both commands offer additional options that allow you to customize the output. For example, you can use the -h option with both commands to display sizes in a human-readable format.
Q: How can I get a summary of disk usage for a directory without including subdirectories?A: With the du command, you can use the -s option to get a summary of disk usage for a directory without including subdirectories. For example: du -sh /path/to/directory.
Q: Are the df and du commands available on all Linux distributions?A: Yes, the df and du commands are standard utilities in Linux and are available on most Linux distributions. However, specific options or output formats may vary slightly between distributions.
Conclusion
In this guide, we unraveled the mystery of df and du commands and provided example commands to analyze and understand disk space usage. When it comes to managing disk space in Linux, df and du commands play a vital role. For beginners, grasping the distinction between these commands and their practical usage is crucial.
Related Read:
- How To Gather Comprehensive Disk Information On Linux
The above is the detailed content of Disk Space Analysis Made Easy: Understanding df And du Commands In Linux. For more information, please follow other related articles on the PHP Chinese website!

The Linux command line interface provides a wealth of text processing tools, one of the most powerful tools is the sed command. sed is the abbreviation of Stream EDitor, a multi-functional tool that allows complex processing of text files and streams. What is Sed? sed is a non-interactive text editor that operates on pipeline inputs or text files. By providing directives, you can let it modify and process text in a file or stream. The most common use cases of sed include selecting text, replacing text, modifying original files, adding lines to text, or removing lines from text. It can be used from the command line in Bash and other command line shells. Sed command syntax sed

Efficiently Counting Files and Folders in Linux: A Comprehensive Guide Knowing how to quickly count files and directories in Linux is crucial for system administrators and anyone managing large datasets. This guide demonstrates using simple command-l

Efficiently managing user accounts and group memberships is crucial for Linux/Unix system administration. This ensures proper resource and data access control. This tutorial details how to add a user to multiple groups in Linux and Unix systems. We

Linux Kernel is the core component of a GNU/Linux operating system. Developed by Linus Torvalds in 1991, it is a free, open-source, monolithic, modular, and multitasking Unix-like kernel. In Linux, it is possible to install multiple kernels on a sing

This brief guide explains how to type Indian Rupee symbol in Linux operating systems. The other day, I wanted to type "Indian Rupee Symbol (₹)" in a word document. My keyboard has a rupee symbol on it, but I don't know how to type it. After

Introduction In the realm of Linux, where the command line is often the compass by which we navigate, the efficient management of disk space is crucial. Whether you’re sailing through personal projects or steering the ship o
![Install Fedora Linux 41 Workstation [Step-by-Step Guide]](https://img.php.cn/upload/article/001/242/473/174149047084567.png?x-oss-process=image/resize,p_40)
This guide provides a comprehensive walkthrough for installing Fedora Linux 41 Workstation Edition. Let's get started! Table of Contents - Step 1: Prepare Your Fedora 41 Installation Media Step 2: Boot from the Fedora 41 Installation Media Step 3:

Linus Torvalds has released Linux Kernel 6.14 Release Candidate 6 (RC6), reporting no significant issues and keeping the release on track. The most notable change in this update addresses an AMD microcode signing issue, while the rest of the updates


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.