Goal: Locate all regular files under /tmp, print their paths one per line, shuffle the list randomly, then print the last item from that shuffled list.
Deliverables:
A single executable Bash script named find_and_shuffle_tmp.sh that performs the steps when run.
The script should print all file paths in the shuffled order, followed by a final line showing the last path from that shuffled list.
If there are no regular files under /tmp, the script should print a concise message and exit gracefully.
How to implement (guidance):
Use find /tmp -type f -print to enumerate files.
Pipe the results into a shuffle utility (shuf) to randomize order.
Output the full shuffled list to stdout.
Print the last item of the shuffled list as a separate line.
Ensure the script handles the no-files case without error.
Make the script executable by running
chmod +x find_and_shuffle_tmp.sh
Run it as
./find_and_shuffle_tmp.sh
Notes:
This task emphasizes simple text processing and the use of standard CLI tools; no external dependencies are required.
The solution should be robust to spaces in file names.