I\'ve tried to change filenames using following script:
find dir/ -type f -exec mv {} $(echo {} | iconv -f UTF8 -t ASCII//TRANSLIT ) \\;
Why doesn\'t it work
The problem with using $()
in this way is that the subshell executes prior to executing the find
command, and not as part of -exec
. You can do it, but you'll need to invoke bash. Something like:
find dir/ -type f -exec bash -c 'mv "$1" "$(iconv -f UTF8 -t ASCII//TRANSLIT <<< $1)"' -- {} \;
Keep in mind this will also translit any special chars in directory names as well, which may cause the mv
to fail. If you only want to translit the filename, then you could:
find dir/ -type f -exec bash -c 'mv "$1" "${1%/*}/$(iconv -f UTF8 -t ASCII//TRANSLIT <<< ${1##*/})"' -- {} \;
which split the directory portion off and only translits the file name.