LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 782|回复: 1

filename-iconv.sh 修改文件名编码

[复制链接]
发表于 2006-5-9 12:58:43 | 显示全部楼层 |阅读模式
终于发现code标签不会去掉空白字符, 呵呵.

  1. #! /bin/bash

  2. # convert file name encoding.
  3. #
  4. # Usage:
  5. #         filename-iconv.sh from_enc to_enc file1 file2 ...
  6. #
  7. # Refer to iconv(1) for available encoding names.
  8. #
  9. # For example, convert GBK file names from Windows to UTF-8
  10. # names in Linux like this:
  11. # (gnome-terminal: Terminal-> Set Character Encoding: UTF-8)
  12. #         ./filename-iconv.sh GBK UTF-8 *
  13. # It should be safe for wrong encoding names or file names
  14. # encoded in ASCII. You can test it before converting:
  15. #         mkdir test_it; for f in *; do touch test_it/$f; done
  16. #         ./filename-iconv.sh GBK UTF-8 test_it/*
  17. #         ls; rm -rf test_it
  18. #
  19. # tip: if you use bash, you can type
  20. #         ./filename-iconv.sh GBK UTF-8 M-*
  21. # to get garbled file names. M-* means press Alt-Shift-9.
  22. #
  23. #
  24. # There is a package named "convmv" doing similar thing.
  25. #

  26. (($# > 2)) &&
  27.             (fe=$1; te=$2; s=""; shift 2;
  28.             for f in $@; do
  29.                     s=`echo -n $f | iconv -f $fe -t $te`
  30.                     (($?)) || /bin/mv -i "$f" "$s"
  31.             done)
复制代码
发表于 2006-5-9 23:20:03 | 显示全部楼层
不错。不过,用 convmv 就搞定了。还有,你的脚本不支持嵌套。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表