2014-07-11 55 views
1

我有一個解壓一批文件目錄中的一個簡單的bash腳本:用gunzip沒有找到文件,即使它知道文件名

#!/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] 

很明顯,它查找目錄中的每個文件,因爲錯誤中列出了文件名,但是卻無法解壓並找不到文件。這裏發生了什麼?

編輯一些文件實際上已得到解壓縮,但該文件的錯誤仍顯示

+0

可以通過'/ volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012725001_012750000.sdf.gz'鏈接嗎? – konsolebox

+0

沒有這些是我手動放置在目錄中的所有文件。 – imkendal

+2

注意檢查這些文件是否真的具有可讀權限? '[[-r /volatile/huanlab/bold/kendal/bioinformatics_database/tmp/compound/Compound_012700001_012725000.sdf.gz]] && echo readable' – konsolebox

回答

2

我想我找到了可能的原因:當您運行gunzip -f $dir/*gz*,該文件被擴大,作爲參數傳遞到gunzip。文件名擴展只發生一次,而不是動態的。即使文件被刪除或重命名,參數仍將保持原樣。不知何故,如果你的某些文件在gzip開始處理之前被刪除(由於解壓每個文件需要一段時間才能到達另一個文件),那麼肯定會出現這些消息。

爲了防止這些信息,你可以檢查每一個文件,如果他們處理之前仍然存在:

for file in "$dir"/*gz; do 
    [[ -f $file ]] && gunzip -f "$file" 
done 
  • 更好的報價$dir防止分詞。
  • 如果目標文件名是以gz結尾的文件名,那麼最後不要多加一個*
+0

這似乎是做到了!非常感謝你 – imkendal

+0

@kjh當然歡迎:) – konsolebox

相關問題