Disk Usage Detective

LinuxLinuxBeginner
Practice Now

Introduction

In this challenge, you'll step into the shoes of a system administrator tasked with investigating disk usage on a Linux server. Your mission is to use the df and du commands to gather crucial information about the file system and directory sizes. These powerful tools will help you analyze disk space utilization and identify potential storage issues.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/SystemInformationandMonitoringGroup -.-> linux/df("`Disk Space Reporting`") linux/SystemInformationandMonitoringGroup -.-> linux/du("`File Space Estimating`") subgraph Lab Skills linux/df -.-> lab-388099{{"`Disk Usage Detective`"}} linux/du -.-> lab-388099{{"`Disk Usage Detective`"}} end

Disk Space Analysis

In this step, you need to analyze disk space usage on a Linux system. You will use the df and du commands to identify the file system with the highest usage percentage, find the total size of a specific directory, and locate the largest subdirectory within that directory.

Tasks

  1. Use the df command to display the disk space usage of all mounted file systems.
  2. Identify the file system with the highest usage percentage.
  3. Use the du command to find the total size of the /home/labex directory.
  4. Locate the largest subdirectory within /home/labex.

Requirements

  • All commands must be executed in the terminal from the ~/project directory.
  • Use the -h option with both df and du commands to display sizes in a human-readable format.
  • When using du to find the largest subdirectory, use the ░░░░░ option to limit the search to immediate subdirectories.
  • Store the output of the df command in a file named disk_usage.txt in the ~/project directory.
  • Store the size of the /home/labex directory in a file named home_size.txt in the ~/project directory.
  • Store the name of the largest subdirectory within /home/labex in a file named largest_subdir.txt in the ~/project directory.

Example

Here's an example of what your ~/project/disk_usage.txt file might look like:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       ░░G   ░░G  ░░G  ░░% /
/dev/sdb1       ░░░G  ░░G  ░░G  ░░% /data
tmpfs           ░░G    ░G  ░░G   ░% /dev/shm

The content of ~/project/home_size.txt might be:

░░░G    /home/labex

And ~/project/largest_subdir.txt might contain:

░░░░░░░░░░

Summary

In this challenge, you've honed your skills in using the df and du commands to analyze disk usage on a Linux system. You've learned how to display disk space information for all mounted file systems, identify high usage areas, and find the sizes of specific directories and subdirectories. These skills are crucial for system administrators in managing storage resources efficiently and proactively addressing potential disk space issues.

Other Linux Tutorials you may like