2013-07-01 1 views
3

현재 디렉토리 아래에서 재귀 적으로 * .html 파일을 압축하려고합니다.현재 디렉토리 아래에있는 모든 HTML 파일을 함께 압축하십시오.

zip all-html-files.zip *.html 

하지만이 반복적으로 작동하지 않습니다

나의 현재 명령입니다. 또한 -r 옵션을 추가해도 보이지 않습니다. 아무도 조언 할 수 있습니까? 현재 디렉토리 아래에있는 하위 디렉토리를 포함하여 모든 HTML 파일을 압축하되 파일 폴더가 아닌 HTML 파일 만 압축합니다.

감사합니다.

답변

7

어떨까요?

find /your/path/ -type f -name "*.html" | xargs zip all_html_files.zip 

디렉토리 /your/path (당신을 위해 변경) 아래의 모든 .html 파일을 찾습니다. 그런 다음 결과를 xargs으로 파이프하면 zip 파일이 만들어집니다. ,

find /your/path/ -type f -name "*.html" | xargs zip -j all_html_files.zip 
+1

, 당신은 경로를 정크 할'-j' 추가 할 수 있습니다. – fedorqui

+0

경로에 공백이 있으면 xargs가 여러 인수로 전달합니다. 'find ... |를 사용하십시오. xargs -I {} zip all_html_files.zip "{}"'. args를 잘못 입력하는 것이 쉽기 때문에'zip'에서 강제로'-output-to-this-file'을 사용하는 것이 조금 위험하다는 것을 알았습니다. – jozxyqk

1

당신이 디렉토리 구조를 유지하지 않으려면

find . -type f -name "*.html" | xargs zip all-html-files 

또한

find . -type f -name "*.html" | zip all-html-files [email protected] 

말할 수보십시오 :

는 경로 정크 -j 옵션을 추가하려면 -j 옵션을 지정하십시오.

find . -type f -name "*.html" | zip -j all-html-files [email protected] 

man zip는 말한다 : 자신의 질문에 표시된 @devnull으로

[email protected] file lists. If a file list is specified as [email protected] [Not on MacOS], zip 
    takes the list of input files from standard input instead of from the 
    command line. For example, 

      zip [email protected] foo 

    will store the files listed one per line on stdin in foo.zip. 

    Under Unix, this option can be used to powerful effect in conjunction 
    with the find (1) command. For example, to archive all the C source 
    files in the current directory and its subdirectories: 

      find . -name "*.[ch]" -print | zip source [email protected] 

    (note that the pattern must be quoted to keep the shell from expanding 
    it). 

    -j 
    --junk-paths 
      Store just the name of a saved file (junk the path), and do not 
      store directory names. By default, zip will store the full path 
      (relative to the current directory). 
+0

어떤 이유인지 이것도 파일 폴더를 압축 -이 스크립트가 파일 폴더를 무시하고 파일을 압축 수있는 방법이 있습니까? – Barney

+0

@Barney는'zip'에'-j' 옵션을 제공합니다. (위 편집 참조) – devnull

관련 문제