zip
圧縮と転送
書き方
zip -r <archive.zip> <path>tar と違って圧縮まで自前で行い、Windows が何も入れずに開けるのはこの形式です。ディレクトリを入れるには `-r` が必要で、付けないと入れ物だけが入って中身は空、`-e` で掛ける錠は古い ZipCrypto なので弱いままです。
よく使うオプション
| オプション | 意味 |
|---|---|
| -r | Recurse into directories. Without it you archive the directory entry and nothing inside. |
| -x '*/node_modules/*' | Exclude a pattern. Quote it so the shell leaves it alone. |
| -e | Prompt for a password. This is legacy ZipCrypto, which is weak. |
| -1 / -9 | Fastest / smallest. |
| -j | Store bare file names and drop the directory structure. |
| -u | Add only files that are new or changed. |
| -s 100m | Split the archive into 100 MB volumes. |
例
zip -r site.zip site -x '*/node_modules/*'The archive a Windows colleague can open, without the dependency tree.
zip -j photos.zip ~/Pictures/*.jpgOne flat archive of files from several places.
まとめることと縮めることは別の仕事です。tar がまとめ、gzip が縮め、.tar.gz はその両方です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. zip は何をしますか。
tar と違って圧縮まで自前で行い、Windows が何も入れずに開けるのはこの形式です。ディレクトリを入れるには `-r` が必要で、付けないと入れ物だけが入って中身は空、`-e` で掛ける錠は古い ZipCrypto なので弱いままです。
Q. どう打ちますか。
zip -r <archive.zip> <path> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man zip にあります。このコマンドは圧縮と転送の仲間です。
関連するコマンド
man ページ: man zip