2011-10-09 6 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

나는 조용한 깃발을 원한다고 생각합니다. 맨 페이지에서

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

은 아마 당신이 아카이브 (-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.*' 
관련 문제