#!/bin/bash for file in *; do # Skip directories to avoid issues if [[ -d "$file" ]]; then continue fi # Store the original filename original_filename="$file" # Initialize an empty string for the new filename temp_name="" new_filename="" # Use IFS to split the filename into words based on spaces IFS=' ' read -ra words <<< "$file" # Iterate through each word and capitalize its first letter for word in "${words[@]}"; do new_filename+="${word^} " done # Trim trailing space new_filename="${new_filename%" "}" temp_name="${new_filename}_temp" # Rename the file if the name has changed if [[ "$original_filename" != "$new_filename" ]]; then mv -v "${file}" "${file}.tmp" && mv -v "${file}.tmp" "${new_filename}" fi done