Categories
Linux

gzip 명령: 리눅스에서 파일을 압축하고 해제하기

1. 파일 1개 압축하기

gzip 명령으로 파일 1개를 압축해 보자.

gzip example.txt

위 명령을 실행하면 example.txt.gz 라는 파일이 생성된다. 압축하기 전의 example.txt 파일은 삭제된다는 점을 주의하자.

압축 전 파일을 삭제하지 않고 보존하려면 -k 옵션을 사용한다.

gzip -k example.txt

2. 여러 파일 압축하기

여러 파일을 한번에 압축해 보자.

gzip a.txt b.txt c.txt

위 명령을 실행하면 a.txt.gz, b.txt.gz, c.txt.gz 가 생성된다.

3. 디렉토리 안의 파일 압축하기

gzip 은 디렉토리를 압축하지 않는다. 대신 디렉토리 안의 파일들을 하나의 명령으로 압축할 수 있다. 이때 -r 옵션을 사용한다.

gzip -r ~/backup/

위 명령은 ~/backup/ 디렉토리 안의 모든 파일을 압축한다.

4. 압축 결과를 1개의 파일에 저장하기

여러 파일과 디렉토리를 압축하여 1개의 파일에 저장하려면 tar 명령이 필요하다.

현재 디렉토리의 모든 파일과 서브 디렉토리를 재귀적으로 압축하여 결과를 backup.tar.gz 파일에 저장해 보자.

tar -czvf backup.tar.gz *

5. 압축 해제

파일의 압축을 해제하여 원본 파일을 복구해 보자. -d 옵션을 사용한다.

gzip -d example.txt.gz

위 명령을 실행하면 example.txt 파일이 복구되고 압축 파일은 삭제된다.

압축을 해제하는 또다른 방법은 gunzip 명령을 사용하는 것이다.

gunzip example.txt.gz

이 경우에도 원본 파일이 복구되면서 압축 파일은 삭제된다.

One reply on “gzip 명령: 리눅스에서 파일을 압축하고 해제하기”

Hi, I hope you’re doing well. I am reaching out because I think you’d be really interested in a product called Jasper AI. It’s a robotic writer powered by arttificial intelligence technologies that curates content material 5x quicker than an average human copywriter. With Jasper AI, you receive 100 original content material with zero plagiarism flags which are accurately written. You also get pre-written templates on specific categories. Jasper AI writes SEO-friendly content material, which means all the content that you get by using Jasper AI is optimized and ready to attract sales. You can try it out at no cost right here: Jasper AI. I would really like to hear your thoughts as soon as you have tried it out.

Leave a Reply

Your email address will not be published. Required fields are marked *