#!/bin/sh # Set the directory to search in (default to root / if not provided) SEARCH_DIR="${1:-/}" # Use find to list all files, shuffle them, and pick one randomly random_file=$(find "$SEARCH_DIR" -type f 2>/dev/null | awk 'BEGIN {srand()} {print rand(), $0}' | sort -k1,1n | cut -d' ' -f2- | head -n 1) # Check if a file was found if [ -n "$random_file" ]; then echo "Randomly selected file: $random_file" else echo "No files found in the specified directory." fi