DEV Community

Pranav Bakare
Pranav Bakare

Posted on

du vs df commands in linux

The du and df commands in Linux both deal with disk usage, but they serve different purposes and provide different kinds of information:

The du command reports the disk space used by files and directories. It calculates the actual space occupied by files within a specified directory or file path.

The df command reports the available disk space on the entire filesystem, including mounted drives. It shows how much space is free, used, and available on the disk partitions, not for specific files or directories.

  1. du (Disk Usage)

The du command reports the disk space used by files and directories. It calculates the actual space occupied by files within a specified directory or file path.

Key Points:

Shows the disk usage of files and directories.

Displays the size of each directory and subdirectory.

Provides an estimate of how much space a directory or file occupies.

Useful for understanding how space is being consumed within a particular directory or file structure.

Common Syntax:

du [options] [directory/file]

Example:

du -h /home/user

-h: Displays the sizes in human-readable format (KB, MB, GB).

This command shows how much space each file and directory under /home/user is using.

Sample Output:

4.0K /home/user/Documents/notes
12M /home/user/Documents/photos
64M /home/user

This output shows the disk usage for each subdirectory under /home/user.

  1. df (Disk Free)

The df command reports the available disk space on the entire filesystem, including mounted drives. It shows how much space is free, used, and available on the disk partitions, not for specific files or directories.

Key Points:

Shows overall disk usage per file system or partition.

Displays the amount of space used and available for mounted filesystems.

Useful for seeing the total disk space usage and available storage on the system.

Common Syntax:

df [options] [filesystem]

Example:

df -h

-h: Displays the sizes in human-readable format (KB, MB, GB).

This command shows the total disk space usage for all mounted filesystems.

Sample Output:

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 30G 18G 63% /
tmpfs 2G 100M 1.9G 5% /tmp
/dev/sdb1 200G 150G 40G 80% /mnt/storage

This output shows the total space, used space, and available space for each mounted filesystem.

Key Differences:

Example Use Case:

du is useful when you need to know which files or directories are using the most space within a folder or across your file system.

df is useful when you want a high-level overview of disk space usage on your entire system, or to see which partitions are running out of space.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

Collapse
 
agokuzeusa profile image
Goku Zeas • Edited

Our platform offers a user-friendly, online Letras chidas 10 tool that allows anyone—from creative enthusiasts to professionals—to generate unique and aesthetically pleasing text styles effortlessly.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay