최근 Vultr와 디지털 오션에서 Ubuntu에 워드프레스를 설치하여 테스트하면서 파일을 압축하거나 압축 해제해야 하는 상황이 많아졌습니다.
Command Line에서 압축을 하거나 압축을 풀 때마다 찾아서 하는 것이 번거로워서 나름대로 정리해보았습니다.
AWS, Vultr, DigitalOcean, 클라우드웨이즈, 블루호스트 VPS 등의 클라우드/VPS 호스팅에서 SSH 접속이 가능합니다. 국내의 경우 카페24에서 권한이 제한적이지만 SSH 접속을 허용합니다. 업로드에 시간이 많이 걸리는 큰 파일들을 업로드하려는 경우 압축 파일로 만들어 FTP/SFTP로 업로드한 후에 SSH에서 압축을 해제하면 시간을 크게 절감할 수 있습니다.
리눅스 SSH Command Line에서 파일 압축/압축 해제하기 [자체 정리용]
Tar 파일
tar 파일 압축 해제하기
tar -xvf file.tar
파일 확장자가 tar.gz인 경우
tar xvzf file.tar.gz
파일 확장자가 tar.tbz인 경우
tar xvjf file.tar.tbz
tar 파일 형식으로 압축을 하려는 경우(참고)
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
폴더를 tar 형식으로 압축하려는 경우 다음과 같은 명령도 가능합니다.
tar cf archive.tar Folder-name
플래그 설명(참고):
- -x : Extract a tar ball.
- -v : Verbose output or show progress while extracting files.
- -f : Specify an archive or a tarball filename.
- -j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
- -z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).
Zip 파일
먼저 zip/unzip을 설치합니다.
sudo apt-get install zip unzip
다음 명령을 사용하여 압축을 해제할 수 있습니다.
unzip photos.zip
하나의 파일만 압축 해제
unzip photos.zip image1.png
다른 폴더에 압축 해제
unzip photos.zip -d ./directory/
무결성을 확신할 수 없을 때 테스트하는 방법. -t 플래그 사용
unzip -t photos.zip
zip 파일 내의 파일 목록을 확인하고 싶은 경우
unzip -l photos.zip
문제가 발생할 경우 man 페이지 확인
man unzip
압축을 하려는 경우(참고)
zip -r my_arch.zip my_folder
파일이 포함된 폴더 삭제:
rm -rf folder_name