0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

zip, unzipメモ

Posted at

目的

運用保守の現場で使用したり先輩から学んだ知識を知識の定着かつ辞書代わりに記録。

zip

ファイルやディレクトリの圧縮、解凍をするコマンド。

基本構文

# 構文
$ zip {{オプション}} {{アーカイブ名}} {{圧縮対象}}

# ファイルの圧縮
$ zip input.zip input.txt

# ディレクトリの圧縮
$ zip -r input.zip input/

パスワードを設定して圧縮

# 構文
# -eオプションをつける
$ zip -e {{アーカイブ名}} {{対象ファイル}}
# または
$ zip -encript {{アーカイブ名}} {{対象ファイル}}

# ファイルの圧縮
# パスワードの入力を2回求められる
$ zip -e input.zip input.txt

# ディレクトリの圧縮
# パスワードの入力を2回求められる
$ zip -er input.zip input/

# パスワードをコマンドにまとめて記述するなら
$ zip -er password=pass input.zip input.txt
※この実行方法はログに残るのでやめた方が良さそう

unzip

基本構文

# 構文
$ zip {{オプション}} {{対象ファイル}}

# ex.)
$ unzip input.zip

パスワード付きzipファイルを解凍する

# 通常通りのunzipコマンドを実行するとパスワードを求められるので入力するだけ
$ unzip input.zip
password:

# オプションに記載する方法もある
$ unzip -P pass input.zip
※この実行方法はログに残るでやめた方が良さそう

文字コードを指定して解凍

解凍する圧縮ファイルの文字エンコードを指定したい場合に使用する。

最初文字化けした際に文字化けしていたので文字コードが異なることに気づき、MacOSではデフォルトはutf-8で解凍されるので、以下オプションでsjisを指定して解凍したところうまくいった。

# 構文
$ unzip -O {{文字コード}} {{解凍zipファイル}}

# sjisで解凍する
$ unzip -O sjis input.zip

※MacOSに既存で入っているunzipコマンドはこのオプションに対応していない場合がある。Homebrewで最新のunzipをインストールすると使えるようになるはず。
$ brew install unzip

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?