File System Explorer

ShellBeginner
Practice Now

Introduction

In this challenge, you'll create a simple file system explorer script that demonstrates your understanding of basic file and directory operations in shell scripting. You'll use file tests to check for existence, type, and permissions of files and directories.

This is a Challenge, which differs from a Guided Lab in that you need to try to complete the challenge task independently, rather than following the steps of a lab to learn. Challenges are usually a bit difficult. If you find it difficult, you can discuss with Labby or check the solution. Historical data shows that this is a beginner level challenge with a 99% pass rate. It has received a 99% positive review rate from learners.

Create the File System Explorer Script

Tasks

  1. Navigate to the ~/project directory where you'll find a partially completed script named file_explorer.sh.
  2. Open the file_explorer.sh file and complete the check_item function to explore file system items.

Requirements

  • The script file_explorer.sh is already created in the ~/project directory with a basic structure.
  • Your task is to complete the check_item function:
    • It should take one parameter (the name of a file or directory).
    • It should perform the following checks and echo the results:
      • If the item exists
      • If it's a file or a directory
      • If it's readable
    • Use appropriate file test operators (-e, -f, -d, -r) for each check.
  • The main part of the script (which calls the function) is already provided.

Example

Here's an example of how the completed script should work:

$ ./file_explorer.sh test_file.txt
Checking: test_file.txt
Exists: Yes
Type: File
Readable: Yes

$ ./file_explorer.sh non_existent.txt
Checking: non_existent.txt
Exists: No

$ ./file_explorer.sh test_directory
Checking: test_directory
Exists: Yes
Type: Directory
Readable: Yes
✨ Check Solution and Practice

Summary

In this challenge, you created a simple file system explorer script using shell scripting. You practiced using file test operators to check for the existence, type, and permissions of files and directories. This exercise reinforced your understanding of basic file system operations in shell scripts, demonstrating practical applications for file and directory management tasks.