How to display disk usage in Linux?

Displaying Disk Usage in Linux

In the Linux operating system, there are several ways to display the disk usage information. The most common and widely used commands are du (disk usage) and df (disk free). These commands provide detailed information about the storage space used and available on your system.

Using the du Command

The du command stands for "disk usage" and is used to estimate file space usage. It can be used to display the disk usage for a specific directory or file, or the entire file system.

Here are some common du command examples:

  1. Display the disk usage of the current directory:

    du

    This will display the total disk usage of the current directory and all its subdirectories.

  2. Display the disk usage of a specific directory:

    du /path/to/directory

    Replace /path/to/directory with the actual path you want to check.

  3. Display the disk usage in a human-readable format:

    du -h

    The -h option stands for "human-readable" and will display the disk usage in a more user-friendly format (e.g., 1.2 GB instead of 1234567890 bytes).

  4. Display the disk usage of the top-level directories only:

    du -d 1 -h

    The -d 1 option limits the output to the top-level directories, and the -h option displays the results in a human-readable format.

  5. Display the disk usage of the top 5 largest directories:

    du -h | sort -hr | head -n 5

    This command first displays the disk usage in a human-readable format, then sorts the output in reverse order (largest to smallest), and finally displays the top 5 largest directories.

Using the df Command

The df command stands for "disk free" and is used to display the available disk space on the file system. It provides information about the total, used, and available space on each mounted file system.

Here are some common df command examples:

  1. Display the disk usage for all mounted file systems:

    df

    This will display the total, used, and available space for each mounted file system.

  2. Display the disk usage in a human-readable format:

    df -h

    The -h option stands for "human-readable" and will display the disk usage in a more user-friendly format (e.g., 1.2 GB instead of 1234567890 bytes).

  3. Display the disk usage for a specific file system:

    df /path/to/directory

    Replace /path/to/directory with the actual path you want to check.

  4. Display the disk usage for all file systems, excluding temporary file systems:

    df -x tmpfs -x devtmpfs

    The -x option allows you to exclude specific file system types from the output.

To better understand the relationship between the du and df commands, here's a Mermaid diagram:

graph TD A[File System] --> B(du) A[File System] --> C(df) B(du) --> D[Disk Usage] C(df) --> E[Disk Free]

The du command provides information about the disk usage of individual files and directories, while the df command displays the overall disk space available and used on the file system. Both commands are useful for understanding the storage utilization on your Linux system.

By using these commands, you can effectively monitor and manage the disk space on your Linux system, ensuring that you have enough storage available for your needs.

0 Comments

no data
Be the first to share your comment!