점으로 시작하는 파일을 포함하여 폴더의 모든 파일과 하위 디렉터리를 압축해야 합니다.

점으로 시작하는 파일을 포함하여 폴더의 모든 파일과 하위 디렉터리를 압축해야 합니다.

.(점)으로 시작하는 파일을 포함하여 폴더의 모든 파일과 하위 디렉터리를 압축해야 합니다 .

저는 이라는 폴더에 있고 synthesis그 아래의 모든 파일과 하위 디렉터리를 압축해야 합니다( synthesis폴더 자체는 아님). 폴더 에는 파일이 들어 있는 synthesis하위 디렉터리가 있습니다 ..sopc_builder

나는 다음 명령을 시도했다

zip -r synthesis.zip *

결과를 synthesis.zip다른 폴더에 복사하고 파일에 zip 내용을 나열했습니다.

unzip -l synthesis.zip > filelist.txt

목록에 파일이 없습니다 filelist.txt..sopc_builder

일부 게시물에서 Linux 명령에 대한 내용을 보았지만 shopt실제로는 이해하지 못했습니다.

제가 사용하는 Linux 버전은 회사의 Red Hat Enterprise Linux Server 7.9입니다.

미리 감사드립니다, 그래디

답변1

그것은 다음과 같아야 합니다:

zip -r file.zip ./

파일이 현재 디렉터리에서 호출 /되면 표준 입력으로 처리되는 버그를 해결하려면 후행이 분명히 필요합니다 .-

glob에 숨겨진 파일을 포함하려면(nor는 아님 .) glob ( glob 한정 자용 ) 을 ..사용할 수 있지만 다음과 같은 여러 가지 이유로 오류가 발생합니다.zsh*(D)Ddotglobzip -r file.zip *(D)zip -r file.zip *

  • -파일 이름이 로 시작하면 실패합니다. 도움이 되겠지만 --이라는 이름의 경우에는 그렇지 않습니다 -../*(D)
  • zip기본적으로 인수를 와일드카드로 처리합니다(MS-DOS 유형 프로그램에 더 가깝습니다). 따라서 파일 이름에 와일드카드 문자(특히 )가 포함되어 있으면 [...]오류가 발생할 수 있습니다. 이를 비활성화 하려면 -nw임의의 파일 이름을 전달할 때 이를 사용합니다.
$ ls -AR
.:
'*'   ...          bar    fifo|      .foo   -h     '[x]'
 -   'a'$'\n''b'   dir/   file.zip   foo    link@

./dir:
-
$ rm -f file.zip; zip -r file.zip ./
        zip warning: ignoring FIFO (Named Pipe) - use -FI to read: ./link
        zip warning: ignoring FIFO (Named Pipe) - use -FI to read: ./fifo
  adding: bar (stored 0%)
  adding: [x] (stored 0%)
  adding: ... (stored 0%)
  adding: .foo (stored 0%)
  adding: a^Jb (stored 0%)
  adding: * (stored 0%)
  adding: - (stored 0%)
  adding: foo (stored 0%)
  adding: dir/ (stored 0%)
  adding: dir/- (stored 0%)
  adding: -h (stored 0%)
$ rm -f file.zip; zip -nw -r file.zip ./*(D)
        zip warning: ignoring FIFO (Named Pipe) - use -FI to read: ./fifo
        zip warning: ignoring FIFO (Named Pipe) - use -FI to read: ./link
  adding: * (stored 0%)
  adding: - (stored 0%)
  adding: ... (stored 0%)
  adding: a^Jb (stored 0%)
  adding: bar (stored 0%)
  adding: dir/ (stored 0%)
  adding: dir/- (stored 0%)
  adding: .foo (stored 0%)
  adding: foo (stored 0%)
  adding: -h (stored 0%)
  adding: [x] (stored 0%)

기본적으로 심볼릭 링크와 fifo가 어떻게 처리되는지 알아보세요. 이 형식은 Microsoft Windows와 같은 다른 운영 체제에서 사용하기 위해 파일을 패키지화하려는 경우에 zip더 잘 사용됩니다 . Unix 파일 아카이브를 만들려면 tar.

답변2

한 가지 방법은 zip다음을 결합하는 것입니다 find.

$ cd the/dir/you/want/to/zip
$ find . -print | zip test -@
adding: file.txt (stored 0%)
adding: .hidden/ (stored 0%)
adding: .hidden/file2.txt (stored 0%)

지시에 따르면

-@ file lists. If a file list is specified as -@ [Not on MacOS],
zip takes the list of input files from standard input instead
of from the command line. For example,
    zip -@ 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 -@ 
(note that the pattern must be quoted to keep the shell from expanding it). 

관련 정보