This task asks you to create a small terminal program that:
selects a random regular file from the list of files in the current directory (non-recursive)
displays the disk usage of each file and directory in the directory hierarchy in a human-readable format
Deliverables:
a script saved at /app/spotlight_du.sh that performs the steps when run
the script prints the path to the randomly chosen file, followed by a hierarchical disk usage listing
Steps:
Create the script at /app/spotlight_du.sh with a POSIX-friendly bash shebang (#!/bin/bash) or /bin/sh.
The script should find one random file in the current directory (non-recursive). Example approach: random_file=$(find . -maxdepth 1 -type f | shuf -n 1)
If no regular file is found, print a friendly message like "No regular files in current directory" and exit 0.
Print "Selected file: "
Print a header "Disk usage for the current directory hierarchy (human-readable):"
Print the disk usage of every file and directory under the current directory using a command such as du -ah . | sort -h
Make the script executable and provide instructions to run it.
Example commands:
chmod +x /app/spotlight_du.sh
/bin/bash /app/spotlight_du.sh
Notes:
The user may have spaces in filenames; if you prefer, you can implement safe handling with -print0 and read loops, but a simple approach using find ... | shuf -n 1 is acceptable.