- 一つのファイルを圧縮
- test1.txtを圧縮して、test1.tar を作成します。
test ディレクトリに移動して、
% ls
test1.txt test2.txt
% tar cvf test1.tar test1.txt
test1.txt
% ls
test1.tar test1.txt test2.txt
%
- 複数のファイルを圧縮
- test1.txt と test2.txt を圧縮して、test.tar を作成します。
test ディレクトリに移動して、
> ls
test1.txt test2.txt
> tar cvf test.tar test1.txt test2.txt
test1.txt
test2.txt
> ls
test.tar test1.txt test2.txt
>
- ディレクトリを圧縮
- test1.txt と test2.txt を含む test ディレクトリを圧縮して、test.tar を作成します。
test ディレクトリの上位のディレクトリに移動して、
> ls
test1.txt test2.txt
> cd ..
> tar cvf test.tar test
test/
test/test1.txt
test/test2.txt
>
- 圧縮されているファイルを見る
- 先に作成した圧縮ファイルを使用して、圧縮されているファイルを見ます。
test ディレクトリの上位のディレクトリに移動して、
> ls test.tar
test.tar
> tar tvf test.tar
drwxr-xr-x kenz/kenz 0 Feb 24 15:28 2002 test/
-rw-r--r-- kenz/kenz 6 Feb 24 15:26 2002 test/test1.txt
-rw-r--r-- kenz/kenz 9 Feb 24 15:26 2002 test/test2.txt
>
- 圧縮ファイルを解凍
- 先に作成した圧縮ファイルを使用して、解凍します。
test ディレクトリの上位のディレクトリに移動して、これまで使用していた test ディレクトリを削除した後に、
> ls
test.tar test
> rm -r test
> ls
test.tar
> tar xvf test.tar
test/
test/test1.txt
test/test2.txt
> ls
test.tar test
>
- 解凍先を指定して圧縮ファイルを解凍
- 先に作成した圧縮ファイルを使用して、解凍します。
test ディレクトリの上位のディレクトリに移動して、test2 というディレクトリを作成して、
> ls
test.tar test test2
> tar xvf test.tar -C test2
test/
test/test1.txt
test/test2.txt
> cd test2
> ls
test
> cd test
> ls
test1.txt test2.txt
- gzip を併用して使用する
- これまでの処理で使用したオプションに z を追加します。圧縮ファイルの拡張子は、tar.gz または tgz を使用します。
| tar zcvf test1.tgz test1.txt |
test1.txt を test.tgz というファイル名で圧縮する |
| tar ztvf test1.tgz |
圧縮ファイル test1.tgz 内のファイルを見る |
| tar zxvf test1.tgz |
圧縮ファイル test1.tgz を解凍 |