1 2 3 4 5 6 7 8
#!/bin/bash for file in $1/*; do TYPE=$(file --mime-type -b "$file" | cut -f2 -d/); if [[ ! $file =~ \.$TYPE ]]; then mv -v "$file" "$file.$TYPE"; fi done