How to recursively convert all filenames in folder subtree from UTF-8 to ASCII in Linux

冷暖自知 提交于 2019-12-08 04:13:10

问题


I'm quiet new to bash scripting, and I would like to convert recursively all my filenames in folder from UTF-8 encoding to ASCII (which is very portable encoding).

I think that iconv command would be of some use:

iconv -f utf8 -t ascii ...

But I'm not sure how to use it exactly. At best the bash script should print some hint about it's progress, like name of file it just converted.
Thank you very much.


回答1:


find /my/path -type f > utf8list
iconv utf8list > asciilist
i=1
for file in $(cat utf8list); do
  newname=$(head -$i asciilist | tail -1 | tr -d '\n')
  #mv $file $newname 
  echo "mv $file $newname"
  let i++
done


来源:https://stackoverflow.com/questions/9929441/how-to-recursively-convert-all-filenames-in-folder-subtree-from-utf-8-to-ascii-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!