웹사이트 검색

초보자를 위한 Linux xz 명령 자습서(예제 7개)


이 페이지에서

  1. Linux xz 명령
  2. Q1. xz 명령을 사용하는 방법?\n
  3. Q2. xz가 원본 파일도 유지하도록 하는 방법은 무엇입니까?\n
  4. Q3. 여러 파일을 압축하는 방법?\n
  5. Q4. .xz 파일의 압축을 푸는 방법은 무엇입니까?\n
  6. Q5. 압축 파일에 대한 xz 인쇄 정보를 만드는 방법은 무엇입니까?\n
  7. Q6. 다른 압축/압축 해제 형식을 지정하는 방법은 무엇입니까?\n
  8. Q7. xz 디스플레이 진행 표시기를 만드는 방법은 무엇입니까?\n
  9. 결론

Linux에서 파일을 압축하고 압축 해제하는 방법에는 여러 가지가 있습니다. 우리는 이미 일부(여기)에 대해 논의했지만 아직 다루지 않은 것이 많습니다. 따라서 여기 이 자습서에서는 이러한 명령줄 유틸리티에 대해 설명합니다.

xz라고 합니다. 이 명령줄 도구의 기본 사항에 대해 설명합니다. 그러나 이에 뛰어들기 전에 여기에 있는 모든 예제가 Ubuntu 18.04 LTS 시스템에서 테스트되었음을 언급할 가치가 있습니다.

리눅스 xz 명령

처음에 이미 언급했듯이 Linux의 xz 명령을 사용하면 파일을 압축하고 압축을 풀 수 있습니다. 구문은 다음과 같습니다.

xz [option...]  [file...]

그리고 매뉴얼 페이지가 그것에 대해 말해야 할 내용은 다음과 같습니다.

     xz is a general-purpose data compression tool with command line syntax similar to gzip(1) 
and bzip2(1).  The native file format is the .xz format, but the legacy .lzma format used
by LZMA Utils and raw compressed streams with no container format headers are also supported.

     xz compresses or decompresses each file according to the selected operation mode.  If no files
are given or file  is  -,  xz  reads from standard input and writes the processed data to
standard output.  xz will refuse (display an error and skip the file) to write compressed data
to standard output if it is a terminal.  Similarly, xz will refuse to read compressed data
from standard  input if it is a terminal.

다음은 xz 작동 방식에 대한 더 나은 아이디어를 제공하는 몇 가지 Q&A 스타일의 예입니다.

Q1. xz 명령을 사용하는 방법?

기본 사용법은 매우 간단합니다. 파일 이름(압축할 파일)을 xz에 대한 입력 인수로 전달하기만 하면 됩니다. 예를 들면 다음과 같습니다.

xz file.txt

내 시스템에서 앞서 언급한 명령은 다음 파일을 출력으로 생성했습니다.

file.txt.xz

따라서 xz 명령으로 압축된 file.txt를 볼 수 있습니다. 작업이 원본 파일(이 경우 file.txt)을 압축된 버전으로 대체한다는 점을 언급할 가치가 있습니다.

Q2. xz가 원본 파일도 유지하도록 하는 방법은 무엇입니까?

이전 섹션에서 언급했듯이 xz 명령은 원본 파일을 압축된 버전으로 바꿉니다. 그러나 원하는 경우 xz가 원본 파일도 유지하도록 강제할 수 있습니다. 이것은 -k 명령줄 옵션을 사용하여 수행할 수 있습니다.

예를 들어:

xz -k file.txt

따라서 이번에는 현재 작업 디렉토리에서 file.txt와 file.txt.xz를 모두 찾을 수 있습니다.

Q3. 여러 파일을 압축하는 방법?

이것은 매우 간단합니다. 이름을 xz에 입력 인수로 전달하기만 하면 됩니다.

예를 들어:

xz file1.txt file2.txt

이 명령은 이 두 파일을 한 번에 압축합니다.

Q4. .xz 파일의 압축을 푸는 방법은 무엇입니까?

.xz 파일의 압축을 풀려면 -d 명령줄 옵션을 사용합니다. 예를 들어:

xz -d file.txt.xz

이 명령은 현재 작업 디렉토리에 file.txt를 생성합니다.

Q5. 압축 파일에 대한 xz 인쇄 정보를 만드는 방법은 무엇입니까?

이것은 -l 명령줄 옵션을 사용하여 수행할 수 있습니다. 예를 들어:

xz -l file.txt.xz

이 명령은 필자의 경우 다음 정보를 생성했습니다.

Strms  Blocks   Compressed Uncompressed  Ratio  Check   Filename
    1       1         96 B         37 B  2.595  CRC64   file.txt.xz

Q6. 다른 압축/압축 해제 형식을 지정하는 방법은 무엇입니까?

이것은 -F 명령줄 옵션을 사용하여 수행할 수 있습니다. 하지만 이 옵션을 사용하려면 다음 사항을 이해해야 합니다.

-F format, --format=format
       Specify the file format to compress or decompress:

       auto   This is the default.  When compressing, auto is equivalent to xz.  When decompressing, the format of the  input  file
              is automatically detected.  Note that raw streams (created with --format=raw) cannot be auto-detected.

       xz     Compress to the .xz file format, or accept only .xz files when decompressing.

       lzma, alone
              Compress  to the legacy .lzma file format, or accept only .lzma files when decompressing.  The alternative name alone
              is provided for backwards compatibility with LZMA Utils.

       raw    Compress or uncompress a raw stream (no headers).  This is meant for advanced users only.  To decode raw streams, you
              need use --format=raw and explicitly specify the filter chain, which normally would have been stored in the container
              headers.

보시다시피 auto, xz, lzma 및 raw 형식 중 하나를 사용할 수 있습니다.

Q7. xz 디스플레이 진행 표시기를 만드는 방법은 무엇입니까?

이것은 -v 명령줄 옵션을 사용하여 가능하게 만들 수 있습니다. 예를 들면 다음과 같습니다.

결론

이 자습서에서 몇 가지 xz 명령줄 옵션에 대해 논의했지만 더 많은 옵션이 있습니다. 이러한 내용을 이해하고 연습한 후에는 도구 설명서 페이지로 이동하여 자세한 내용을 알아보세요.