zip 아카이브에서 하나의 파일을 업데이트하는 방법
압축을 풀지 않고 새 파일을 추가하고 다시 압축하지 않고 zip 파일의 파일을 바꿀 수 있습니까?
이유는 내가 가끔 업데이트해야하는 zip 파일 내에 하나의 xml이있는 정말 큰 zip 파일이 있다는 것입니다. zip 압축을 풀고 다시 압축하는 데 시간이 오래 걸립니다. 그래서 스크립트를 통해 zip 안에있는 하나의 xml을 바꿀 수 있기를 원합니다. 나는 이미 가지고있는 xml에 대한 업데이트를 확인했습니다.
그래서 압축을 풀고 다시 압축하지 않고 하나의 xml을 바꿀 수 있습니까?
죄송합니다. zip 명령을 사용하여 이와 같은 작업을 수행하지만 문제는 스크립트가 실제로 안드로이드 폰용이며 zip은 사용할 수있는 명령이 아니라는 점입니다. 내가 할 수 있다면 zip을 확실히 사용했을 것이지만 droid에 대해서만 압축을 풀고 busybox에 tar가 있지만 tar가 필요한 작업을 수행하지 않습니다.
에서 지퍼 (1) :
기존 zip 아카이브의 이름이 주어지면 zip은 zip 아카이브에서 동일한 이름의 항목을 대체하거나 새 이름에 대한 항목을 추가합니다.
따라서 zip
지정하는 .zip 파일 이름이 기존 아카이브가되는 것을 제외하고는 해당 파일 하나만 포함하는 새 .zip 파일을 만들 때 일반적으로 사용하는 명령을 사용하십시오 .
Linux zip
파일은 zip에서 단일 파일을 바꾸는 데 번거 롭다 는 것을 알았습니다 . jar
Java Development Kit 의 유틸리티가 더 쉬울 수 있습니다. WEB/web.xml
JAR 파일 (단지 zip 파일)에서 업데이트하는 일반적인 작업을 고려하십시오 .
jar -uf path/to/myapp.jar -C path/to/dir WEB-INF/web.xml
여기에 path/to/dir
디렉토리가 포함 된 WEB-INF
디렉토리 의 경로가 있습니다 (이 차례로 포함됨 web.xml
).
다음을 시도하십시오.
zip [zipfile] [file to update]
예 :
$ zip test.zip test/test.txt
updating: test/test.txt (stored 0%)
나는 이것이 오래된 질문이라는 것을 알고 있지만 똑같이하고 싶었습니다. zip 아카이브의 파일을 업데이트합니다. 그리고 위의 답변 중 어느 것도 나를 정말로 도왔습니다.
내가 한 일은 다음과 같습니다. 임시 디렉토리를 생성했습니다 abc
. 복사 file.zip
에 abc
해당 디렉토리에 파일을 추출 하였다. 편집하고 싶은 파일을 편집했습니다. 그런 다음에있는 동안 abc
다음 명령을 실행했습니다.
user@host ~/temp/abc $ zip -u file.zip
updating: content/js/ (stored 0%)
updating: content/js/moduleConfig.js (deflated 69%)
-u
스위치는 변경된 / 새 파일을 찾고 zip 아카이브에 추가합니다.
업데이트 플래그를 사용하십시오. -u
예:
zip -ur existing.zip myFolder
이 명령은 압축 myFolder
하여 existing.zip
.
고급 사용법 :
업데이트 플래그는 실제로 들어오는 파일을 기존 파일과 비교하고 새 파일을 추가하거나 기존 파일을 업데이트합니다.
따라서 zip 파일 내에서 특정 하위 디렉토리를 추가 / 업데이트하려면 원하는대로 소스를 업데이트 한 다음 -u
플래그로 전체 소스를 다시 압축하면 됩니다. 변경된 파일 만 압축됩니다.
소스 파일에 액세스 할 수없는 경우 zip 파일의 압축을 풀고 원하는 파일을 업데이트 한 다음 -u
플래그를 사용하여 다시 압축 할 수 있습니다 . 다시 말하지만, 변경된 파일 만 압축됩니다.
예:
원본 소스 구조
ParentDir
├── file1.txt
├── file2.txt
├── ChildDir
│ ├── file3.txt
│ ├── Logs
│ │ ├── logs1.txt
│ │ ├── logs2.txt
│ │ ├── logs3.txt
업데이트 된 소스 구조
ParentDir
├── file1.txt
├── file2.txt
├── ChildDir
│ ├── file3.txt
│ ├── Logs
│ │ ├── logs1.txt
│ │ ├── logs2.txt
│ │ ├── logs3.txt
│ │ ├── logs4.txt <-- NEW FILE
용법
$ zip -ur existing.zip ParentDir
> updating: ParentDir/ChildDir/Logs (stored 0%)
> adding: ParentDir/ChildDir/Logs/logs4.txt (stored 96%)
You can use: zip -u file.zip path/file_to_update
There is also the -f option that will freshen the zip file. It can be used to update ALL files which have been updated since the zip was generated (assuming they are in the same place within the tree structure within the zip file).
If your file is named /myfiles/myzip.zip all you have to do is
zip -f /myfiles/myzip.zip
From the side of ZIP archive structure - you can update zip file without recompressing it, you will just need to skip all files which are prior of the file you need to replace, then put your updated file, and then the rest of the files. And finally you'll need to put the updated centeral directory structure. However, I doubt that most common tools would allow you to make this.
7zip
(7za) can be used for adding/updating files/directories nicely:
Example: Replacing (regardless of file date) the MANIFEST.MF
file in a JAR file. The /source/META-INF
directory contains the MANIFEST.MF
file that you want to put into the jar
(zip):
7za a /tmp/file.jar /source/META-INF/
Only update (does not replace the target if the source is older)
7za u /tmp/file.jar /source/META-INF/
yes its possible.
on linux based systems just install zip and you can call it in the command line. have a look at the manpage: http://linux.die.net/man/1/zip
but in my personal experience, if possible and compression is not so important, this works better with plain tar files and tar.
참고URL : https://stackoverflow.com/questions/4799553/how-to-update-one-file-in-a-zip-archive
'Program Tip' 카테고리의 다른 글
Apple FFT 및 Accelerate Framework 사용 (0) | 2020.11.03 |
---|---|
Javascript에서 isEmpty를 확인하고 있습니까? (0) | 2020.11.03 |
PHP에서 사용자 에이전트를 얻는 방법 (0) | 2020.11.03 |
rspec을 실행할 때 Rails.logger에서 콘솔 / stdout으로 인쇄하는 방법은 무엇입니까? (0) | 2020.11.03 |
Numpy : 범위 내의 요소 찾기 (0) | 2020.11.03 |