사용이 간편함:

사용이 간편함:

경로를 알고 있는 ZIP 파일에서 단일 파일을 추출해야 합니다. 다음과 유사한 명령이 있습니까?

unzip -d . myarchive.zip path/to/zipped/file.txt

안타깝게도 위 명령은 파일의 전체 경로를 추출하고 다시 생성합니다 ./path/to/zipped/file.txt. 파일을 지정된 디렉토리로 간단히 가져올 수 있는 방법이 있습니까?

답변1

다음 옵션을 사용하면 텍스트만 표준 출력으로 추출할 수 있습니다 -p.

unzip -p myarchive.zip path/to/zipped/file.txt >file.txt

이것은 메타데이터(날짜, 권한 등)를 추출하지 않고 파일 내용만 추출합니다(분명히 일반 파일에만 작동하고 심볼릭 링크, 장치, 디렉토리는 작동하지 않습니다...). 나중에 파일을 이동할 필요가 없는 편리함을 위해 지불하는 비용입니다.

또는 아카이브를 디렉터리로 마운트하고 파일만 복사합니다. 그리고AVFS:

mountavfs
cp -p ~/.avfs"$PWD/myarchive.zip#"/path/to/zipped/file.txt .

또는퓨즈 지퍼:

mkdir myarchive.d
fuse-zip myarchive.zip myarchive.d
cp -p myarchive.d/path/to/zipped/file.txt .
fusermount -u myarchive.d; rmdir myarchive.d

답변2

unzip -j "myarchive.zip" "in/archive/file.txt" -d "/path/to/unzip/to"

파일 이름뿐만 아니라 압축 파일의 전체 경로를 입력하세요. zip 파일의 구조를 유지해야 합니다.

그러면 개별 파일이 file.txt.myarchive.zip/path/to/unzip/to/file.txt


-j: 정크 경로. 아카이브의 디렉터리 구조는 다시 생성되지 않습니다. 모든 파일은 압축이 풀린 디렉터리에 배치됩니다(기본값은 현재 디렉터리).

-d: 파일을 추출할 선택적 디렉터리입니다.

https://www.mankier.com/1/unzip


여러 파일:

unzip -j myarchive.zip in/archive/file.txt another/file.ext -d /path/to/unzip/to

전체 하위 디렉터리

unzip -j archive.zip "sub/dir/*" -d "dest/dir"

답변3

더 간단한 버전:

unzip ARCHIVE_NAME PATH_OF_FILE_INSIDE_ARCHIVE

그러면 PATH_OF_FILE_INSIDE_ARCHIVE현재 디렉터리가 다시 생성되지만 지정된 파일만 추출됩니다.

Zip 아카이브의 모든 파일을 나열하려면:

unzip -l ARCHIVE_NAME

답변4

사용이 간편함:

unzip zipfile.zip path/inside/zip/file.txt

파일이 부풀어 오를 것입니다.

$ unzip -l ./../html.zip | grep wp-config

     3328  07-22-2019 15:10   html/wp-config.php

     2898  01-07-2019 23:30   html/wp-config-sample.php

$ unzip ./../html.zip html/wp-config.php

     Archive:  ./../html.zip
     inflating: html/wp-config.php

$ ls -lrth

     total 4.0K
     drwxr-sr-x 2 apache apache 4.0K Jul 26 14:41 html

$ ls -lrth html/*

     total 4.0K
     -rw-rw-rw- 1 apache apache 3.3K Jul 22 15:10 wp-config.php

관련 정보