Linux find重新编码所有文件到子目录

标签 linux encoding find iconv

我正在尝试重新编码目录中的所有文件并将结果放入子目录中。 我正在使用

find . -type f -name '*.txt' -execdir iconv -f utf-16 -t utf-8 {} >  reencoded/{} \;

但是文件名不会替换第二次出现的“{}”,而是会在 reencoded/{} 中出现结果。

最佳答案

将该命令包含在对 sh -c 的调用中,然后可以将 {} 引用为 $0:

find . -type f -name '*.txt' -execdir sh -c 'iconv -f utf-16 -t utf-8 "$0" >  reencoded/"$0"' {} \;

关于Linux find重新编码所有文件到子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31145024/

相关文章:

linux - 使用 find -name 命令的通配符和双引号

linux - 如何在引导时捕获整个内核 panic

encoding - Jasper 报告 PDF 编码

mysql - 对 MySQL 使用 UTF-8

search - 查找文本,不包括 Sublime 中的超集

jQuery 的多重选择器 + find() 与 Children()

linux - nasm 汇编 linux 计时器或 sleep

linux - 以编程方式检查 Linux 时钟的健全性

python - 从 python 读取 BerkleyDB 文件 : `\x01\x0b\x88\x0c\x01` ?

linux - 在 Linux 上删除除 .git 目录和 .gitignore 之外的所有内容