Skip to main content

Checking Disk Space with df and du

Checking Disk Space with df and du Checking Disk Space with df and du

Checking Disk Space with df and du

Understanding the df Command

The df command is used to display the amount of disk space available on the filesystem. It provides an overview of the space utilization on all mounted filesystems.

Syntax:

df [options] [filesystems]

Common Options:

  • -h: Human-readable format, displaying sizes in KB, MB, GB, etc.
  • -T: Displays the type of filesystem.
  • -i: Displays inode usage.

Examples:

Basic Usage:

df

This command outputs the disk space usage of all mounted filesystems.

Human-Readable Format:

df -h

The -h option provides a more readable output, using units like KB, MB, and GB.

Including Filesystem Type:

df -T

The -T option displays the type of each filesystem.

Understanding the du Command

The du command is used to estimate file and directory space usage. Unlike df, which shows overall filesystem usage, du provides details on specific directories and files.

Syntax:

du [options] [directories]

Common Options:

  • -h: Human-readable format.
  • -a: Displays usage for all files, not just directories.
  • -s: Provides a summary of the total disk usage for the specified directories.
  • -c: Adds a grand total at the end of the output.

Examples:

Basic Usage:

du

This command outputs the disk usage of the current directory and its subdirectories.

Human-Readable Format:

du -h

The -h option provides a more readable output.

Summarizing Disk Usage:

du -sh

The -s and -h options together provide a summarized and human-readable output of the current directory's usage.

Including All Files:

du -ah

The -a option includes all files in the output.

Practical Use Cases

Combining df and du:

Checking Overall Usage and Identifying Large Directories:

df -h

Review the overall disk usage, then identify large directories:

du -sh /*

This command lists the disk usage of all directories at the root level, helping you pinpoint which ones consume the most space.

Finding Large Files:

du -ah / | sort -n -r | head -n 10

This command lists the top 10 largest files and directories in the root directory.

Conclusion

Effective disk space management is crucial for maintaining optimal system performance. The df and du commands are powerful tools that provide comprehensive insights into disk usage. By combining these commands and utilizing their options, you can monitor and manage your disk space efficiently, ensuring your system runs smoothly.

© 2025 Linux Playground

Comments

Popular posts from this blog

Understanding sudo and su: A Comprehensive Guide

Understanding sudo and su: A Comprehensive Guide Understanding sudo and su : A Comprehensive Guide What is sudo ? The sudo (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. Essentially, sudo grants temporary administrative privileges to perform a specific task. Key Features of sudo : Granular Control: sudo allows system administrators to delegate limited root access to users, specifying exactly which commands they are permitted to run. Auditability: Every use of sudo is logged, providing a clear trail of who used sudo , what commands were executed, and when. Temporary Elevation: sudo grants elevated privileges for the duration of a single command, reducing the risk of accidental system-wide changes. Sec...

Using ping, traceroute, and netstat for Network Diagnostics

Using ping, traceroute, and netstat for Network Diagnostics Using ping, traceroute, and netstat for Network Diagnostics In the complex world of networking, diagnosing and troubleshooting issues is essential for maintaining a healthy and efficient network. Three fundamental tools often used for these purposes are ping , traceroute , and netstat . Each of these utilities offers unique insights into network performance and connectivity. Let's dive into their functionalities, use cases, and how they can be employed effectively. 1. Ping: Checking Connectivity and Latency The ping command is one of the most straightforward and commonly used network diagnostic tools. It tests the reachability of a host on an Internet Protocol (IP) network and measures the round-trip time for messages sent from the source to a destination computer. How It Works: The ping command sends Inte...

Understanding the Sticky Bit and Its Role in File Security

Understanding the Sticky Bit and Its Role in File Security Understanding the Sticky Bit and Its Role in File Security File security is a critical aspect of managing any computing environment. Among the several mechanisms and permissions available to ensure files and directories are protected, the sticky bit is one of the lesser-known but powerful tools. This article aims to provide a comprehensive understanding of the sticky bit, how it functions, and its implications for file security. What is the Sticky Bit? The sticky bit is a permission setting that can be applied to files and directories in Unix and Unix-like operating systems such as Linux. Originally, it was used to indicate that a program's executable should be retained in memory after its initial execution to improve performance. However, this functionality has become largely obsolete with modern memory mana...