遍历当前目录下的文件,然后按行读取文件名进行转码。
字符编码问题
#!/bin/bash
ls . | while read filename
do
echo $filename
echo -n $filename | iconv -f UTF-8 -t ISO-8859-1 | iconv -f gbk
echo ""
mv "$(echo -n $filename)" "$(echo -n $filename | iconv -f UTF-8 -t ISO-8859-1 | iconv -f gbk)"
done
ÖйúÃñÀÖ£ºÅýÅÃ
中国民乐:琵琶
urldecode
#!/bin/bash
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
ls . | while read filename
do
echo $filename
urldecode $(echo -n $filename)
echo ""
mv "$(echo -n $filename)" "$(urldecode $(echo -n $filename))"
done
%E7%90%B5%E7%90%B6%20--%20%E5%85%A5%E9%97%A8
琵琶 -- 入门
Ref:
[1] https://beisongnansong.wordpress.com/2018/08/26/linux%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81%E8%A7%A3%E5%86%B3/
[2] https://stackoverflow.com/questions/6250698/how-to-decode-url-encoded-string-in-shell

该博客提供了两个bash脚本,分别用于处理Linux目录下文件名的编码转换(从UTF-8到ISO-8859-1和GBK)以及URL编码的解码。脚本通过`ls`、`while`循环和`iconv`命令实现文件名的编码转换,并使用`mv`命令重命名文件。此外,还展示了URL解码的函数及其应用,帮助用户理解并解决字符编码和URL编码问题。
1013

被折叠的 条评论
为什么被折叠?



