我有一个简单的bash脚本,它解压缩目录中的一堆文件:
#!/bin/bash
dir=/volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound
gunzip -f $dir/*gz*然而,当我运行这个命令时,我会得到以下错误:
gzip: /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012650001_012675000.sdf.gz: No such file or directory
gzip: /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012675001_012700000.sdf.gz: No such file or directory
gzip: /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012700001_012725000.sdf.gz: No such file or directory
gzip: /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012725001_012750000.sdf.gz: No such file or directory
... [this continues on for every file in the directory]很明显,它正在查找目录中的每个文件,因为文件名是在错误中列出的,但是它无法解压缩它们,并表示找不到该文件。这里发生什么事情?
编辑中的一些文件实际上被解压缩了,但是该文件的错误仍然显示
发布于 2014-07-11 17:52:17
我想我找到了一个可能的原因:当您运行gunzip -f $dir/*gz*时,文件会被展开并作为参数传递给gunzip。文件名扩展只发生一次,而不是动态的。即使文件被删除或重命名,参数也将保持原样。如果您的一些文件在gzip开始处理它们之前就被删除了(因为解压缩每个文件需要时间才能到达另一个文件),那么这些消息肯定会出现。
为了防止这些消息,您可以在处理之前检查每个文件是否仍然存在:
for file in "$dir"/*gz; do
[[ -f $file ]] && gunzip -f "$file"
done$dir以防止分词。gz结尾的文件名,那么在末尾不要增加一个*。https://stackoverflow.com/questions/24703374
复制相似问题