Linux(Ubuntu)에서 zip, unzip 명령어로 압축 및 압축 해제하는 명령어를 소개합니다.
- 파일 압축
- 특정 폴더 및 그 하위 파일들 압축
- 압축 해제
- 특정 경로에 압축 해제
1. zip 명령어로 폴더 및 파일 압축
-r
옵션을 사용하면 폴더 및 그 하위에 있는 모든 폴더 및 파일들을 모두 압축할 수 있습니다.
$ zip -r [output file name] [target folder]
# ex) zip -r abc.zip ./abc
두개 이상의 폴더 및 파일을 압축할 때도, 다음과 같이 폴더 및 파일 경로들을 나열하면 됩니다.
$ zip -r [output file name] [target folder1] [target folder2] [target file]
# ex) zip -r abc.zip ./abc ./mydir ./text1.txt ./text2.txt
Example: 1개 폴더 압축
다음과 같이 resources 폴더와 하위 파일들을 압축하여 output.zip
파일로 저장할 수 있습니다.
$ zip -r output.zip resources/
adding: resources/ (stored 0%)
adding: resources/SEC-INF/ (stored 0%)
adding: resources/SEC-INF/buildConfirm.crt (deflated 13%)
adding: resources/SEC-INF/buildinfo.xml (deflated 41%)
adding: resources/assets/ (stored 0%)
adding: resources/assets/NOTICE (deflated 65%)
adding: resources/AndroidManifest.xml (deflated 84%)
adding: resources/classes.dex (deflated 62%)
...
$ ls
output.zip resources
Example: 2개 이상의 폴더 및 파일 압축
아래와 같이 2개의 디렉토리와 2개의 파일을 output.zip
파일로 압축할 수 있습니다.
$ zip -r output.zip resources/ sources/ text1.txt text2.txt
updating: resources/ (stored 0%)
updating: resources/SEC-INF/ (stored 0%)
updating: resources/SEC-INF/buildConfirm.crt (deflated 13%)
updating: resources/SEC-INF/buildinfo.xml (deflated 41%)
Example: 파일만 압축
만약 파일만 압축한다면 -r
옵션을 사용하지 않고 다음과 같이 압축할 수 있습니다.
$ zip output.zip text1.txt text2.txt
adding: text1.txt (deflated 79%)
adding: text2.txt (deflated 79%)
$ ls
output.zip text1.txt text2.txt
2. unzip 명령어로 압축 풀기
다음과 같이 unzip으로 압축을 해제할 수 있습니다.
$ unzip [file name]
# ex) unzip abc.zip
특정 폴더에 압축을 풀고 싶으면 -d
옵션으로 타겟 폴더를 설정하시면 됩니다.
$ unzip [file name] -d [target folder]
# ex) unzip abc.zip -d ./myfolder
Example: 압축 해제
아래와 같이 output.zip
을 압축 해제할 수 있습니다. 파일들은 Working directory에 저장됩니다.
$ unzip output.zip
extracting: resources/res/drawable-mdpi/ic_arrow_down_24dp.webp
extracting: resources/res/drawable-mdpi/sesl_ic_commit_search_api_alpha.webp
....
$ ls
output.zip resources sources text1.txt text2.txt
Example: 특정 폴더에 압축 해제
만약 특정 폴더에 압축 해제하고 싶다면, -d
옵션으로 폴더를 지정할 수 있습니다. 다음은 mydir
폴더에 output.zip
을 압축 해제하는 예제입니다.
$ unzip output.zip -d ./mydir
extracting: resources/res/drawable-mdpi/ic_arrow_down_24dp.webp
extracting: resources/res/drawable-mdpi/sesl_ic_commit_search_api_alpha.webp
....
$ ls ./mydir
output.zip resources sources text1.txt text2.txt
위의 명령어를 실행했을 때 mydir
폴더 아래에 동일한 파일이 있으면, 아래와 같이 덮어쓸 것인지 물어봅니다.
$ unzip output.zip -d mydir/
Archive: output.zip
replace mydir/resources/SEC-INF/buildConfirm.crt? [y]es, [n]o, [A]ll, [N]one, [r]ename:
Loading script...
Related Posts
- Ubuntu에서 draw.io 설치하는 방법
- 리눅스 deb 파일 설치
- 우분투에 VMware 설치하기
- [Ubuntu] VMware에서 Windows 11 설치
- Vi/Vim에서 1줄 또는 여러줄 삭제 방법
- Vi/Vim에서 라인 번호 표시하기
- 우분투에서 rar 압축, 압축 풀기
- Ubuntu에서 구글 드라이브 사용하기 (로컬 폴더에 마운트)
- [Ubuntu] apt-cache search, 설치 가능한 패키지 검색
- Ubuntu - DNS 캐시 삭제 방법
- Ubuntu에서 사용할 수 있는 Text Editor 소개
- 우분투(리눅스) - RAM(메모리) 크기 확인
- 우분투에서 시간대(Timezone) 변경하기
- 우분투(리눅스)에서 Atom 텍스트 에디터 설치
- 우분투(리눅스)에서 Microsoft Edge 브라우저 설치
- 우분투(리눅스)에서 Slack 설치
- 우분투(리눅스)에서 Visual Studio Code 설치
- Linux - 파일, 디렉토리 삭제 명령어(rm -rf, rmdir)
- Linux - 파일이 수정된 날짜/시간 확인 방법
- Linux - touch로 파일 생성, 파일의 날짜/시간 변경
- Linux - Node.js로 Html 파일을 로컬 서버에서 실행하기
- Linux - zip, unzip으로 압축 및 압축 해제
- 우분투 - Linux 커널 삭제 방법
- Ubuntu에서 Right ALT를 한영키로 변환
- Linux 파일 권한 소개 및 권한 변경
- Linux - Image resize, Format 변경 명령어
- Ubuntu - Gradle 최신 버전 설치 방법
- Ubuntu - Notepad++ 설치 방법
- Ubuntu - Python 3.9 설치 방법
- Ubuntu - Sublime Text 4 설치 방법
- Ubuntu - nodejs LTS, 최신 버전 설치
- Proxy 환경에서 pip 사용 방법
- 최신 코드로 업데이트하는 repo sync 명령어
- Linux - 디렉토리 용량 확인
- Linux - IP 주소 확인