Portál AbcLinuxu, 12. května 2025 11:06
Řešení dotazu:
for file in *; do mv -v $file `echo $file | iconv -f [KODOVÁNÍ NÁZVŮ SOUBORŮ] -t ASCII//TRANSLIT`; done
#!/bin/bash IFS=' ' find -type f | while read file do newfile=`echo $file | iconv -f [UTF-8] -t ASCII//TRANSLIT` mv -v $file $newfile doneJenze tam bylo velke mnozstvi nazvu souboru se znaky typu ctvrtecek, sipka atp. (netusim proc), ktere byly nahrazeny otaznikem ... takze ted bych jeste potreboval vyresit, jak vymenit otazniky treba za X ... :)
#!/bin/bash IFS=' ' find -type f | while read file do rename s/?/X $file doneAle neustale mi to vraci chybu "Substitution replacement not terminated at (eval 1) line 1." coz zrejme souvisi s chybnym nastavenim prikazu rename. Jestli nekdo vite, co s tim, tak se nebranim rade :), ale ted musim letet spat ... :D
# v Debian/Ubuntu/Mint: sudo apt-get install convmv # rekurzivne pouze otestovat jak by jmena prevadelo z windows 1250 convmv -r -f cp1250 -t utf8 * # nebo z pc latin 2 convmv -r -f cp852 -t utf8 * # nebo z iso latin 2 convmv -r -f iso-8859-2 -t utf8 * # pokud ok, tak realne prevest (s tim spravnym -f codovanim) convmv -r -f cp1250 -t utf8 --notest *
michal@mobile-250gb /mount/dataspace/Downloads/TEMP/Stasheff, Christopher $ convmv -r -f cp1250 -t utf8 *Starting a dry run without changes... Skipping, already UTF-8: ./Èarodìj-[00-08]-Uniková-rychlost.pdb Skipping, already UTF-8: ./Èarodìj-[01]-Èarodìjem-sobì-navzdory.pdb Skipping, already UTF-8: ./Èarodìj-[02]-Vzkøíšení-krále-skøeta.pdb Skipping, already UTF-8: ./Èarodìj-[03]-Odpoutaný.pdb No changes to your files done. Use --notest to finally rename the files. michal@mobile-250gb /mount/dataspace/Downloads/TEMP/Stasheff, Christopher $ convmv -r -f cp852 -t utf8 * Starting a dry run without changes... Skipping, already UTF-8: ./Èarodìj-[00-08]-Uniková-rychlost.pdb Skipping, already UTF-8: ./Èarodìj-[01]-Èarodìjem-sobì-navzdory.pdb Skipping, already UTF-8: ./Èarodìj-[02]-Vzkøíšení-krále-skøeta.pdb Skipping, already UTF-8: ./Èarodìj-[03]-Odpoutaný.pdb No changes to your files done. Use --notest to finally rename the files. michal@mobile-250gb /mount/dataspace/Downloads/TEMP/Stasheff, Christopher $ convmv -r -f iso-8859-2 -t utf8 * Starting a dry run without changes... Skipping, already UTF-8: ./Èarodìj-[00-08]-Uniková-rychlost.pdb Skipping, already UTF-8: ./Èarodìj-[01]-Èarodìjem-sobì-navzdory.pdb Skipping, already UTF-8: ./Èarodìj-[02]-Vzkøíšení-krále-skøeta.pdb Skipping, already UTF-8: ./Èarodìj-[03]-Odpoutaný.pdb No changes to your files done. Use --notest to finally rename the files.
STARE="Èìø" NOVE="Čěř" find . -type f | while read file; do path="${file%/*}" oldfile="${file##*/}" newfile="$(<<<"$oldfile" | tr "$STARE" "$NOVE")" if [ "$oldfile" != "$newfile" ]; then echo mv "$path/$file" "$path/$newfile" fi donePokud to pojede, tak stačí dát
echo
pryč. V dalším kroku je potřeba obdobně přejmenovat adresáře, ale nechce se mi to vymýšlet. Tam už to jeden find
nespraví a bude potřeba rekurzivně procházet skriptem adresářovou strukturou, v aktuálním adresáři všechny podadresáře přejmenovat a sestoupit o úroveň hlouběji.
--nosmart by default convmv will detect if a filename is already UTF8 encoded and will skip this file if conversion from some charset to UTF8 should be performed. "--nosmart" will also force conversion to UTF-8 for such files, which might result in "double encoded UTF-8" (see section below). --fixdouble using the "--fixdouble" option convmv does only convert files which will still be UTF-8 encoded after conversion. That's useful for fixing double-encoded UTF-8 files. All files which are not UTF-8 or will not result in UTF-8 after conversion will not be touched. Also see chapter "How to undo double UTF-8 ..." below.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.