简体   繁体   English

/ usr / bin / find:循环bash脚本的参数列表过长

[英]/usr/bin/find: Argument list too long in for loop bash script

I have such a bash script. 我有这样的bash脚本。 I want to gzip all .ppm files under a directory to another directory. 我想将一个目录下的所有.ppm文件gzip 压缩到另一个目录。 For this reason I have written such a bash script: 因此,我编写了这样的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

When I execute this script, I get such error: 执行此脚本时,出现以下错误:

/usr/bin/find: Argument list too long

How can I fix this problem? 我该如何解决这个问题?

Quote this part : *.ppm to prevent filename globbing, and also remove the ! 引用此部分: *.ppm以防止文件名*.ppm ,并删除! as you want to find files with .ppm extension, not the other way around. 因为您要查找扩展名为.ppm文件,而不是相反。

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


Instead of running a loop you could do it with single find command which would provide white space safety: 除了运行循环之外,您还可以使用单个find命令来执行此操作,以提供空白空间安全性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM