2011-10-09 16 views
7

私はbashシェルを使用してファイルを圧縮したいので、私が使用:bashで 'zip'警告を無効にするにはどうすればよいですか?

echo -n 'Insert the file path:' 
read path 
echo 'Hello World' > ${path} 
zip -u ${path}.zip ${path} 

私はこのスクリプトを実行すると、それは私に警告できます:

zip warning: test.zip not found or empty 
adding: test (deflated 66%) 

をそれがうまく動作しますが、どのようにすることができますこの警告を無効にしますか?正しい方法でzipを使用していますか?

答えて

18

私はあなたが静かな旗をしたいと思う。 manページから

zip -uq ${path}.zip ${path} 

-q 
--quiet 
      Quiet mode; eliminate informational messages and comment 
      prompts. (Useful, for example, in shell scripts and background 
      tasks). 
+0

+1私が探している何が。ありがとう:) –

1

多分あなたの代わりに更新(-u)の "追加" してみてください? manページから

add 
      Update existing entries and add new files. If the archive does not exist 
      create it. This is the default mode. 

    update (-u) 
      Update existing entries if newer on the file system and add new files. 
      If the archive does not exist issue warning then create a new archive. 

    freshen (-f) 
      Update existing entries of an archive if newer on the file system. Does 
      not add new files to the archive. 

    delete (-d) 
      Select entries in an existing archive and delete them. 
1

おそらくあなたは、アーカイブ(-u)を更新するzipに伝えるべきではありません。 -uスイッチを使用しないと、zipはアーカイブにファイルを追加しようとし、警告なしで存在しないアーカイブを作成する必要があります。

0

不要な出力行を削除して通常のステータス情報を表示することもできますが、stderrをstdoutにリダイレクトする必要があります。たとえば、次のコマンドは、多くのzipファイルから特定のファイルのみを抽出しますが、空行を表示したり、見つからないファイルには不平を書きません。そのようにしてあなたはまだ伐採のためのいくつかの出力を持って、デバッグなど

unzip -jn archivedlogfiles\* \*logfile\* 2>&1 | grep -vE '^$|^caution.*' 
Archive: archivedlogfiles1.zip 
    inflating: little_logfile_20160515.log 
    inflating: little_logfile_20160530.log 
Archive: archivedlogfiles2.zip 
Archive: archivedlogfiles3.zip 
Archive: archivedlogfiles4.zip 
Archive: archivedlogfiles5.zip 
Archive: archivedlogfiles6.zip 
Archive: archivedlogfiles7.zip 
Archive: archivedlogfiles8.zip 
    inflating: little_logfile_20160615.log 
    inflating: little_logfile_20160630.log 
Archive: archivedlogfiles9.zip 
2 archives were successfully processed. 
7 archives had fatal errors. 

基本的にはあなたのコマンドは次のようになります。

zip -u ${path}.zip ${path} 2>&1 | grep vE '^zip\swarning.*' 
関連する問題