linux -/usr/bin/找到 : Argument list too long in for loop bash script

标签 linux bash find quoting glob

我有这样一个 bash 脚本。我想gzip 一个目录下的所有.ppm 文件到另一个目录。为此我写了这样一个bash脚本:

cd /export/students/sait/12-may
for next_file in  $(find . -type f  ! -name *.ppm )
do
/bin/gzip -f -c $next_file > /export/students/sait/12-may-yedek/$next_file.gz
done

当我执行这个脚本时,我得到这样的错误:

/usr/bin/find: Argument list too long

我该如何解决这个问题?

最佳答案

引用此部分:*.ppm 以防止文件名通配,并删除 ! 因为你想查找带有 .ppm 的文件扩展,而不是相反。

find . -type f  -name '*.ppm'


您可以使用单个 find 命令来代替运行循环,这将提供空白安全:

find /export/students/sait/12-may -type f -name '*.ppm' -exec sh -c '/bin/gzip -f -c "$0" > "$0".gz' {} \;

关于linux -/usr/bin/找到 : Argument list too long in for loop bash script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241091/

相关文章:

linux - 在 bash 脚本中查找命令导致目录出现 "No such file or directory"错误?

bash - 编写一个 shell 脚本,在 1 行中查找并输出文件名和内容

linux - 用户进程、终端和内核之间的通信

linux - 执行 bash 脚本和手动执行有区别吗?

c - 如何在 C 中创建 Linux 管道示例

bash - 我可以在远程服务器上运行位于本地机器上的 bash 脚本吗?

linux - BASH grep 脚本

mysql - 在 Controller 中执行 find 指定基本条件,但 cakephp 构建的查询与条件不匹配

linux - 是在某处调用的脚本

linux - 在 linux 中查找所有包含字符串的文件