【问题标题】:gunzip not finding files even though it knows file namesgunzip 即使知道文件名也找不到文件
【发布时间】:2014-07-11 17:32:28
【问题描述】:

我有一个简单的 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]

显然它正在查找目录中的每个文件,因为文件名列在错误中,但随后它无法解压缩并说找不到文件。这是怎么回事?

编辑有些文件确实被解压了,但仍然显示该文件的错误

【问题讨论】:

  • /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012725001_012750000.sdf.gz 可以作为链接吗?
  • 不,这些都是我手动放入目录的文件。
  • 介意检查这些文件是否真的具有可读权限? [[ -r /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012700001_012725000.sdf.gz ]] && echo readable
  • 这里是ls -al 在该目录-r--r--r-- 1 kharland jhuangroup 5609 Jul 6 15:30 Compound_009525001_009550000.sdf.gz 上的输出,所有文件都具有这些确切的权限。有趣的建议,我没想过这样做。我也刚刚意识到你给了我一个命令,输出结果是空的
  • 我可以猜到这是某个地方的错误。如果不在 gunzip 中,它可能在其中一个库中。如果您改用gzip -d /path/to/file.gz 会有所不同吗?我很好奇你的 gzip 版本:gzip --version

标签: bash zip gzip


【解决方案1】:

我想我找到了可能的原因:当您运行gunzip -f $dir/*gz* 时,文件被扩展并作为参数传递给gunzip。文件名扩展只发生一次并且不是动态的。即使文件被删除或重命名,参数也会保持原样。不知何故,如果您的某些文件在gzip 开始处理它们之前被删除(因为解压缩每个文件需要一些时间才能到达另一个文件),那么这些消息肯定会出现。

为了防止这些消息,您可以在处理之前检查每个文件是否仍然存在:

for file in "$dir"/*gz; do
    [[ -f $file ]] && gunzip -f "$file"
done
  • 最好引用$dir 以防止分词。
  • 如果目标文件名是以gz 结尾的文件名,则不要在末尾添加额外的*

【讨论】:

  • 这似乎做到了!非常感谢
猜你喜欢
  • 2014-02-20
  • 2015-10-26
  • 2016-05-18
  • 1970-01-01
  • 2018-04-07
  • 2015-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多