Display Filesystem Free Space Utilization

LinuxLinuxIntermediate
Practice Now

Introduction

The freeSpace.sh script is designed to display the names of any file-system which have less than n% free space available. It makes use of the df, tr and cut commands to retrieve information about the file-systems present in the system and then filters out the ones that have less than n% free space remaining.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/InputandOutputRedirectionGroup(["`Input and Output Redirection`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) shell(("`Shell`")) -.-> shell/BasicSyntaxandStructureGroup(["`Basic Syntax and Structure`"]) shell(("`Shell`")) -.-> shell/VariableHandlingGroup(["`Variable Handling`"]) shell(("`Shell`")) -.-> shell/AdvancedScriptingConceptsGroup(["`Advanced Scripting Concepts`"]) shell(("`Shell`")) -.-> shell/SystemInteractionandConfigurationGroup(["`System Interaction and Configuration`"]) shell/ControlFlowGroup -.-> shell/if_else("`If-Else Statements`") linux/BasicFileOperationsGroup -.-> linux/cut("`Text Cutting`") linux/BasicSystemCommandsGroup -.-> linux/source("`Script Executing`") linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/InputandOutputRedirectionGroup -.-> linux/pipeline("`Data Piping`") linux/InputandOutputRedirectionGroup -.-> linux/redirect("`I/O Redirecting`") linux/BasicSystemCommandsGroup -.-> linux/read("`Input Reading`") linux/FileandDirectoryManagementGroup -.-> linux/which("`Command Locating`") linux/SystemInformationandMonitoringGroup -.-> linux/df("`Disk Space Reporting`") shell/BasicSyntaxandStructureGroup -.-> shell/shebang("`Shebang`") shell/BasicSyntaxandStructureGroup -.-> shell/comments("`Comments`") shell/BasicSyntaxandStructureGroup -.-> shell/quoting("`Quoting Mechanisms`") shell/VariableHandlingGroup -.-> shell/variables_decl("`Variable Declaration`") shell/VariableHandlingGroup -.-> shell/variables_usage("`Variable Usage`") shell/VariableHandlingGroup -.-> shell/str_manipulation("`String Manipulation`") shell/VariableHandlingGroup -.-> shell/arrays("`Arrays`") shell/VariableHandlingGroup -.-> shell/param_expansion("`Parameter Expansion`") shell/ControlFlowGroup -.-> shell/for_loops("`For Loops`") shell/ControlFlowGroup -.-> shell/cond_expr("`Conditional Expressions`") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_ops("`Arithmetic Operations`") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_expansion("`Arithmetic Expansion`") shell/AdvancedScriptingConceptsGroup -.-> shell/read_input("`Reading Input`") shell/AdvancedScriptingConceptsGroup -.-> shell/cmd_substitution("`Command Substitution`") shell/AdvancedScriptingConceptsGroup -.-> shell/subshells("`Subshells and Command Groups`") shell/SystemInteractionandConfigurationGroup -.-> shell/globbing_expansion("`Globbing and Pathname Expansion`") subgraph Lab Skills shell/if_else -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/cut -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/source -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/echo -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/pipeline -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/redirect -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/read -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/which -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} linux/df -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/shebang -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/comments -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/quoting -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/variables_decl -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/variables_usage -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/str_manipulation -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/arrays -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/param_expansion -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/for_loops -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/cond_expr -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/arith_ops -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/arith_expansion -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/read_input -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/cmd_substitution -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/subshells -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} shell/globbing_expansion -.-> lab-18309{{"`Display Filesystem Free Space Utilization`"}} end

Free Space

In this challenge, you are provided with a script that is designed to display the names of any file-systems which have less than a specified percentage of free space available.

Tasks

You need to complete the following task:

  • Modify the script to display all file-systems present in the system
  • Enhance the script to print file-systems that have less than the specified percentage of memory remaining

Requirements

You must meet the following requirements:

  • The script should be named freeSpace.sh
  • Work directory should be ~/project
  • Familiarity with df, tr, cut, working with arrays and loops is required
  • The script should prompt the user to enter the usage percentage

Example

Example 1:

labex:project/ $ bash freeSpace.sh
[INPUT] Enter the usage [INPUT]
12
file system "/dev/mapper/docker-252:3-1311728-cf1bc296802376b110e1ac0a19ed3ad263fc81be8ff146ddfbd4acc246b61682" has "62%" of freespace and used space of 38%
file system "/dev/vda3" has "54%" of freespace and used space of 46%

Example 2:

labex:project/ $ bash freeSpace.sh
[INPUT] Enter the usage [INPUT]
60
No file System has usage of 40% of freeSpace

Summary

After completing this challenge, you will have gained a better understanding of how to retrieve information about file-systems in a Linux system and how to filter and manipulate that information using various commands and tools. You will also have learned how to use arrays and loops in Bash scripting to automate tasks and make your code more efficient. Additionally, you will have improved your problem-solving skills by designing a script that addresses a specific problem and provides a solution in a concise and effective manner.

Other Linux Tutorials you may like