2011-10-09 12 views
7

मैं bash खोल का उपयोग कर एक फ़ाइल ज़िप करना चाहते, तो मैं प्रयोग किया है:बैश में 'ज़िप' चेतावनी को अक्षम कैसे करें?

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

मुझे लगता है कि आप शांत ध्वज चाहते हैं।

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)?

आदमी पृष्ठ से

:

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

शायद आप zip बता नहीं करना चाहिए एक संग्रह (-u) अद्यतन करने के लिए। -u स्विच zip किसी संग्रह में फ़ाइलों को जोड़ने का प्रयास करता है, और बिना चेतावनियों के गैर-मौजूदा संग्रह बनाना चाहिए।

0

आप अनावश्यक आउटपुट लाइनों को भी हटा सकते हैं और सामान्य स्थिति की जानकारी को छोड़ सकते हैं, लेकिन आपको पहले stderr को stdout पर रीडायरेक्ट करने की आवश्यकता है। उदाहरण के लिए निम्न कमांड केवल कुछ विशिष्ट फाइलों से निकालेंगे, लेकिन खाली फ़ाइलों को नहीं दिखाएगा और न ही फाइलों के लिए शिकायत करेगा। कि जिस तरह से में आप अभी भी प्रवेश के लिए कुछ उत्पादन, डिबगिंग आदि

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.*' 
संबंधित मुद्दे