0
0
Linux CLIscripting~15 mins

df (disk free space) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Check Disk Free Space with df Command
📖 Scenario: You are managing a Linux server and want to check how much disk space is free on your system. This helps you avoid running out of space and keep your server running smoothly.
🎯 Goal: Learn to use the df command to display disk free space information and filter the output to see only the root filesystem usage.
📋 What You'll Learn
Use the df command to show disk space usage
Use a variable to store the filesystem name /
Use grep to filter the output for the root filesystem
Print the filtered disk space information
💡 Why This Matters
🌍 Real World
System administrators often need to monitor disk space to prevent servers from running out of space, which can cause crashes or data loss.
💼 Career
Knowing how to use basic Linux commands like <code>df</code> and scripting with variables and conditionals is essential for roles in system administration, DevOps, and IT support.
Progress0 / 4 steps
1
Create a variable for the root filesystem
Create a variable called root_fs and set it to the string "/" to represent the root filesystem.
Linux CLI
Need a hint?

Use root_fs="/" to store the root filesystem path.

2
Run the df command and filter for root filesystem
Use the df -h command piped to grep with the variable root_fs to filter the output and show only the disk space info for the root filesystem. Store this output in a variable called root_usage.
Linux CLI
Need a hint?

Use root_usage=$(df -h | grep " $root_fs$") to get the filtered disk space info.

3
Print the root filesystem disk usage
Print the content of the variable root_usage to display the disk free space information for the root filesystem.
Linux CLI
Need a hint?

Use echo "$root_usage" to print the disk usage info.

4
Add a check to show a message if root filesystem info is missing
Add an if statement to check if root_usage is empty. If it is empty, print "Root filesystem info not found.". Otherwise, print the root_usage variable.
Linux CLI
Need a hint?

Use if [ -z "$root_usage" ] to check if the variable is empty.