Create a dated tarball of the five most recently modified files (random order)
Objective
Produce a gzip-compressed tarball named with the current date (format: YYYY-MM-DD.tar.gz).
The archive should contain exactly the five most recently modified regular files from the current directory, but the order of those files inside the tarball should be randomized.
What to prepare
You should be in the target directory that contains the files.
Regular files only should be included; directories and hidden files are ignored unless there are fewer than five regular files (in which case include all available regular files).
if [ -n "$files" ]; then
tar czf "$filename" $files
echo "Created $filename containing:"
tar -tf "$filename" | tr '\n' ' '
else
echo "No regular files found to archive."
fi
Deliverables
A tarball named with the current date, e.g., 2025-10-26.tar.gz, in the current directory.
Optional verification: tar -tzf 2025-10-26.tar.gz should list the included files in the random order chosen.
Notes
The approach picks the five most recently modified regular files (by modification time) and then shuffles their order before archiving.
If there are fewer than five eligible files, the tarball will contain all of them.