脚本 – BSD – 以递归方式从目录中的所有文件中删除非ascii字符

我正在尝试将一堆(300GB)文件从FAT32驱动器迁移到我的freeNas ZFS文件系统,但是我抛出的每个命令(tar,pax,mv,cp)在遇到非命令时会抛出“无效参数” ASCII文件名 – 它通常是在Windows下创建的东西,它读的是“foo?s bar.mp3 …”中的内容.可能是撇号等.

任何人都可以帮助使用几行代码递归遍历目录树并重命名文件以删除有问题的字符.

非常感激.

最佳答案
尝试将iocharset选项设置为其使用的编码来安装文件系统.

从man mount下的“Mount options for fat”部分:

   iocharset=value
          Character set to use for converting between 8 bit characters and
          16 bit Unicode characters. The default is iso8859-1.  Long file‐
          names are stored on disk in Unicode format.

另请参阅“为vfat安装选项”部分:

   uni_xlate
          Translate  unhandled  Unicode  characters  to  special   escaped
          sequences.   This lets you backup and restore filenames that are
          created with any Unicode characters. Without this option, a  '?'
          is used when no translation is possible. The escape character is
          ':' because it is otherwise illegal on the vfat filesystem.  The
          escape  sequence  that gets used, where u is the unicode charac‐
          ter, is: ':', (u & 0x3f), ((u>>6) & 0x3f), (u>>12).

   utf8   UTF8  is  the  filesystem safe 8-bit encoding of Unicode that is
          used by the console. It can be be  enabled  for  the  filesystem
          with this option or disabled with utf8=0, utf8=no or utf8=false.
          If `uni_xlate' gets set, UTF8 gets disabled.

编辑:

对不起,那是Linux,这是针对BSD的(来自man mount_msdosfs:

 -L locale
     Specify locale name used for file name conversions for DOS and
     Win'95 names.  By default ISO 8859-1 assumed as local character
     set.

 -D DOS_codepage
     Specify the MS-DOS code page (aka IBM/OEM code page) name used
     for file name conversions for DOS names.

转载注明原文:脚本 – BSD – 以递归方式从目录中的所有文件中删除非ascii字符 - 代码日志