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!

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

Wine 10.0 stable version release: Running Windows applications on Linux to a higher level Wine, this open source and free application, allows Linux users to run Windows software and games on Unix/Linux operating systems, ushering in the release of the 10.0 stable version! This version has been provided with source code and binary package downloads, and supports various distributions such as Linux, Windows and Mac. This edition embodies a year of hard work and over 8,600 improvements, bringing many exciting improvements. Key highlights include: Enhanced support for Bluetooth devices. Improve support for HID input devices. Optimized performance of 32-bit and 64-bit applications.

This tutorial guides you through installing SQL Server 2022 on RHEL 8.x or 9.x, connecting via the sqlcmd command-line tool, database creation, and basic querying. Prerequisites Before beginning, ensure: A supported RHEL version (RHEL 8 or 9). Sudo

Mozilla Thunderbird 135: Powerful cross-platform mail client Mozilla Thunderbird is a free, open source, cross-platform email, calendar, news, chat and contact management client designed to efficiently handle multiple email accounts and news sources. On February 5, 2025, Mozilla released the Thunderbird 135 version, introducing a number of new features, performance improvements and security fixes. Thunderbird 135 main features: XZ Packaging for Linux Binaries: Smaller files, faster unpacking, and better integration with modern distributions. Cookie storage support: when creating space

This guide demonstrates how to protect files on Linux from accidental renaming or deletion using simple commands. We'll use the file important.txt in /home/user/ as an example. Method 1: Using chattr for Immutability The chattr command modifies fil


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor
