0
  1. Changing from Linux Mint Cinammon to Mint KDE causes something with the filenames char sets of all partitions! Now the names are messed. I've already tried to change locales, unsuccessfully
  2. The problem concerns accented characters (I'm a brazilian portuguese speaker)
  3. The big problem is that I have to deal with approximately 60GB+ of 60.000+ files (PDFs mainly), in 1000+ folders and subfolders in a fat32 partition
  4. So I found over internet this command line that works fine for me, but it lacks the recursive feature, i.e., it does not apply the changes to the subfolders, and the files contained in subfolders. It just apply the desired changes (that is: rename the file from one char set to another) to the actual plain single folder

My question is: How to turn this command line recursive? Is it even possible?

ls -1 | while read arquivo ; do novo="`echo $arquivo \
| iconv -f UTF-8 -t ISO-8859-1`"; if [ "$novo" != "$arquivo" ] ;\
then mv "$arquivo" "$novo"; fi done
rkta
  • 3,959
  • 7
  • 25
  • 37

1 Answers1

0

This should do the trick:

find . -type f -exec bash -c 'novo="`echo $1 \                                
| iconv -f UTF-8 -t ISO-8859-1`"; if [ "$novo" != "$1" ] ;\
then mv "$1" "$novo"; fi' -- {} \

You may change . to any directory appropriate and filter files by name with -name, see man find.

To only affect files ending in .pdf you could use

find . -type f -name '*.pdf' -exec bash -c 'novo="`echo $1 \                                
| iconv -f UTF-8 -t ISO-8859-1`"; if [ "$novo" != "$1" ] ;\
then mv "$1" "$novo"; fi' -- {} \

One-liner for copy&paste:

find . -type f -exec bash -c 'novo="`echo $1 | iconv -f UTF-8 -t ISO-8859-    1`"; f [ "$novo" != "$1" ] ; then mv "$1" "$novo"; fi' -- {} \;
rkta
  • 3,959
  • 7
  • 25
  • 37
  • Tried this out, yeah! 1) it's recursive, 2) do the trick. But... my output was this one for all files (br-portuguese). I'm missing something? "mv: não foi possível mover './.local/share/Trash/files/2017.2/ética livros novos/SINGER, P. Ã'$'\302\211''tica prática.pdf' para './.local/share/Trash/files/2017.2/ética livros novos/SINGER, P. Ética prática.pdf': Arquivo ou diretório não encontrado" Typed this way: "find . -type f -exec bash -c 'novo="`echo $1 | iconv -f UTF-8 -t ISO-8859-1`"; if [ "$novo" != "$1" ] ; then mv "$1" "$novo"; fi' -- {} \;" – José Paulo Maldonado Sep 15 '18 at 17:25
  • Sorry rkta, by now I'm still testing the command line. Just tried to specify folder and extension, with little success. My feelings tell this is the way to go, thanks, I'll leave a comment soon showing my concrete results and asking for further help or improvement!! – José Paulo Maldonado Sep 18 '18 at 15:56
  • I have just founded out this command, my problem is solved: `convmv -r --notest -f windows-1252 -t UTF-8 *` . Thanks! – José Paulo Maldonado Sep 25 '18 at 16:24