Adding random suffixes to filenames I would like to change the filename of a lot of files by adding a random suffix to the existing filenames.  

I have tried to change this code (changes the filename instead of adding a suffix) but with no succes.

#!/bin/bash

chars=( {a..z} {A..Z} {0..9} )

function rand_string {
    local c=$1 ret=
    while((c--)); do
        ret+=${chars[$((RANDOM%${#chars[@]}))]}
    done
    printf '%s\n' "$ret"
}

for file in ~/Desktop/test/*; do
    ext=$(echo ${file} | sed 's,^.*(\.[^\.]*$),\1,')
    mv "$file" ~/Desktop/test/"$file$(rand_string 10)"${ext}
done


A command line or automator solution would be preferable
If you just want to append a randomized string the for loop is rather simple:

cd ~/Desktop/test/
for file in *; do
    suffix="${file##.*}"
    base="${file%.*}"
    mv "$file" "$base.$(rand_string 10).$suffix"
done


Change the 10 to the number of random characters you want to add.