将 iconv 应用于目录中的所有文件

que*_*zal 5 command-line bash utf-8

在尝试转换 .srt 文件集合时:

iconv -f cp1256 -t utf-8 directory/* > target/*
Run Code Online (Sandbox Code Playgroud)

它将目录中的所有 22 个文件转换为目标目录中名为 *. 我希望处理后的文件单独出现在目标目录中。有人可以帮忙吗?

kar*_*rel 8

cd path-to-source-directory
find . -name "*.srt" -exec iconv -f CP1256 -t UTF-8 {} -o path-to-destination-directory/{} +
Run Code Online (Sandbox Code Playgroud)

例子:

如果 source-directory 称为 SOURCE,destination-directory 称为 DESTINATION,并且两个目录都位于桌面上,则 path-to-source-directory 是~/Desktop/SOURCE,path-to-destination-directory 是~/Desktop/DESTINATION

  • find: -exec 仅支持一个 {} 实例 ... + :( (3认同)