cd /var/www/screenshots # Start the HTML document cat << 'EOF' > index.html Screenshots Listing

Screenshots

EOF # Loop through files (excluding index.html) and output table rows for f in *; do if [[ "$f" != "index.html" && -f "$f" ]]; then # Get human readable size, last modification date size=$(stat -c%s "$f") # Convert size to human readable form if [ $size -lt 1024 ]; then hsize="${size} B" elif [ $size -lt 1048576 ]; then hsize=$(awk "BEGIN {printf \"%.1f KB\", $size/1024}") else hsize=$(awk "BEGIN {printf \"%.1f MB\", $size/1048576}") fi modtime=$(stat -c %y "$f" | cut -d'.' -f1) # Add table row with link echo " " >> index.html fi done # Close the table and add footer cat << 'EOF' >> index.html
NameSizeLast Modified
$f$hsize$modtime
EOF