はじめに
今回はファイルの圧縮・解凍で用いるコマンドを扱います。
gzip コマンド
gz 形式でファイルを圧縮・解凍するコマンド
コマンド | 説明 |
---|---|
gzip -d(gunzip) | ファイルを解凍する |
gzip -r | ディレクトリ内のファイルも再帰的に圧縮する |
例(ファイルの圧縮)
[ec2-user@localhost ~]$ gzip file.txt
[ec2-user@localhost ~]$ ls file.txt*
file.txt.gz
例(ファイルの解凍)
[ec2-user@localhost ~]$ gzip -d file.txt.gz
[ec2-user@localhost ~]$ ls file.txt*
file.txt
zip、unzip コマンド
zip 形式で圧縮・解凍するコマンド
コマンド | 説明 |
---|---|
zip -r | ディレクトリ内のファイルも再帰的に圧縮してディレクトリを圧縮する |
例(zip形式でファイルを圧縮)
[ec2-user@localhost ~]$ zip file.txt.zip file.txt
adding: file.txt (stored 0%)
[ec2-user@localhost ~]$ ls file.txt.zip
file.txt.zip
例(zip形式の圧縮ファイルを解凍)
[ec2-user@localhost ~]$ unzip file.txt.zip
tar コマンド
ファイル・ディレクトリをさまざまな形式で圧縮・解凍するコマンド
コマンド | 説明 |
---|---|
tar -c | 圧縮する |
tar -x | 解凍する |
tar -f | 対象のファイル・ディレクトリを指定する |
tar -v | 処理されたファイルの一覧を表示 |
tar -z | gzip形式で圧縮・解凍( .tar.gz という拡張子になる ) |
tar -j | xz形式で圧縮・解凍( .tar.xz という拡張子になる ) |
例(ディレクトリを tar.xz で圧縮)
[ec2-user@localhost ~]$ tar -cvJf dir1.tar.xz dir1
dir1/
dir1/file1
例(ファイルを解凍)
[ec2-user@localhost ~]$ tar -xvJf dir1.tar.xz
dir1/
dir1/file1
おわりに
ファイル転送で大活躍!