Linux 명령어 · 2 min read · Sep 14, 2025

초보자를 위한 Linux bzip2 명령어 튜토리얼 (6가지 예제)

파일 압축은 특정 알고리즘에 따라 수행됩니다. 압축 기술은 여러 가지가 있으며, 그 중 하나는 bzip2를 통해 이루어집니다. 이 튜토리얼에서는 이해하기 쉬운 몇 가지 예제를 통해 bzip2의 기본을 배워보겠습니다. 이 기사에서 사용된 모든 예제는 Ubuntu 22.04LTS 머신에서 테스트되었습니다.

Linux bzip2 명령어

bzip2는 Burrows-Wheeler 블록 정렬 텍스트 압축 알고리즘과 허프만 코딩을 사용하여 압축 프로세스를 수행하는 Linux의 명령줄 기반 파일 압축기입니다. 다음은 그 구문입니다:

bzip2 [OPTIONS] filenames ...

그리고 이 도구에 대한 man 페이지의 설명은 다음과 같습니다:

       bzip2  compresses  files  using  the Burrows-Wheeler block sorting text  
       compression algorithm, and Huffman coding.   Compression  is  generally  
       considerably   better   than   that   achieved   by  more  conventional  
       LZ77/LZ78-based compressors, and approaches the performance of the  PPM  
       family of statistical compressors.  
  
       The  command-line options are deliberately very similar to those of GNU  
       gzip, but they are not identical.  
  
       bzip2 expects a list of file names to accompany the command-line flags.  
       Each  file is replaced by a compressed version of itself, with the name  
       "original_name.bz2".  Each compressed file has  the  same  modification  
       date,  permissions,  and, when possible, ownership as the corresponding  
       original, so that these properties can be correctly restored at  decom?  
       pression  time.  File name handling is naive in the sense that there is  
       no mechanism for preserving original file  names,  permissions,  owner?  
       ships  or dates in filesystems which lack these concepts, or have seri?  
       ous file name length restrictions, such as MS-DOS.

다음은 bzip2 명령어가 어떻게 작동하는지에 대한 좋은 아이디어를 제공하는 Q&A 스타일의 예제입니다.

Q1. bzip2를 사용하여 파일을 압축하는 방법은?

기본 사용법은 매우 간단합니다 - 압축할 파일을 bzip2 명령어에 입력으로 전달하기만 하면 됩니다. 다음은 예제입니다:

bzip2 list.txt

다음 스크린샷은 명령어가 실행되는 모습을 보여줍니다:

Q2. bzip2를 사용하여 여러 파일을 압축하는 방법은?

간단합니다 - 파일 이름을 입력으로 전달하기만 하면 됩니다. 다음 예제를 참조하세요:

bzip2 list.txt list1.txt list2.txt

Q3. bzip2를 사용하여 압축 해제하는 방법은?

압축 해제를 위해서는 -d 명령줄 옵션을 사용합니다. 다음은 예제입니다:

bzip2 -d list.txt.bz2

Q4. bzip2가 입력 파일을 삭제하지 않도록 하려면?

기본적으로 bzip2가 파일을 압축하면 원본(또는 입력) 파일을 삭제합니다. 그러나 그렇게 하고 싶지 않다면 -k 명령줄 옵션을 사용하세요.

다음은 예제입니다:

Q5. bzip2가 각 압축 작업에 대한 세부 정보를 표시하도록 하려면?

이는 -v 명령줄 옵션을 사용하여 수행할 수 있습니다. 다음은 man 페이지에서 설명하는 내용입니다:

-v --verbose  
              Verbose  mode -- show the compression ratio for each file processed.  Further -v's   
              increase the verbosity level, spewing out lots of information which is primarily of   
              interest for diagnostic purposes.

다음은 -v가 사용될 때 bzip2 명령어 출력이 표시되는 예제입니다:

Q6. 압축된 파일의 무결성을 확인하는 방법은?

bzip2 명령어는 .bz2 파일의 무결성을 확인하는 데에도 사용할 수 있습니다(파일이 손상되지 않았거나 생성 이후 변경되지 않았는지 확인하는 테스트). 이는 -t 명령줄 옵션을 사용하여 수행할 수 있습니다.

-t --test  
     Check  integrity of the specified file(s), but don't decompress them.    
     This really performs a trial decompression and throws away the result.

결론

bzip2 명령줄 유틸리티는 훨씬 더 많은 옵션을 제공하지만, 여기서 논의한 내용만으로도 시작하기에 충분해야 합니다. 이 튜토리얼에서 논의한 옵션을 연습한 후에는 도구의 man 페이지로 가서 더 많은 정보를 배울 수 있습니다.

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.