Linuxでファイルを圧縮および解凍する方法はいくつかあります。すでにいくつか(こことここで)議論しましたが、まだ議論していないことがたくさんあります。したがって、ここでは、このチュートリアルで、別のそのようなコマンドラインユーティリティについて説明します。
吹き替えxz 。このコマンドラインツールの基本について説明します。しかし、それに飛び込む前に、ここでのすべての例はUbuntu18.04LTSマシンでテストされていることを言及する価値があります。
Linuxxzコマンド
すでに冒頭で述べたように、Linuxのxzコマンドを使用すると、ファイルを圧縮および解凍できます。その構文は次のとおりです。
xz [option...] [file...]
そして、これがmanページがそれについて言わなければならないことです:
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コマンドの圧縮ファイル.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コマンドラインオプションについて説明しましたが、他にもたくさんあります。これらの理解と実践が終わったら、ツールのマニュアルページにアクセスして詳細を確認してください。