如何转换递归文件夹中的子树的所有文件名从UTF-8 ASCII在Linux中 [英] How to recursively convert all filenames in folder subtree from UTF-8 to ASCII in Linux

查看:158
本文介绍了如何转换递归文件夹中的子树的所有文件名从UTF-8 ASCII在Linux中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很安静的新bash的脚本,我想所有的递归我从文件名UTF-8编码转换成文件夹为ASCII(这是非常便携编码)。

我认为iconv命令将一些使用的:

 的iconv -f -t UTF8 ASCII ...

但我不知道如何准确地使用它。
最好的情况是bash脚本应该打印一些暗示它的进步,如文件只是转换的名字。结果
非常感谢你。


解决方案

 查找/我的/路径型的F> utf8list
的iconv utf8list> asciilist
I = 1
在$文件(猫utf8list);做
  NEWNAME = $(头 - $ I asciilist |尾-1 | TR -d的'\\ n')
  #mv $​​文件$ NEWNAME
  回声MV $文件$ NEWNAME
  让我++
DONE

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.

解决方案

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

这篇关于如何转换递归文件夹中的子树的所有文件名从UTF-8 ASCII在Linux中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆