10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コマンドラインでzipを作るコマンドまとめ

Last updated at Posted at 2019-04-28

基本

zip zipname * 
  • 現在のディレクトリ内の全てのファイルを対象に
  • zipnameという名前のzipファイルを作る

現在のディレクトリ配下のファイル全てはいったzipを作る

zip -r zipname * 
  • 現在のディレクトリ配下の全てのファイルを対象に
  • zipnameという名前のzipファイルを作る

-rをつけることでディレクトリ配下のファイルも対象にできる。
zip zipname * だけだと、現在のディレクトリにフォルダがあった場合、フォルダ配下はzipに含まれない。

特定の拡張子の全ファイルが入ったzipを作る

zip zipname *.js
  • 現在のディレクトリ内の拡張子がjsのファイルを対象に
  • zipnameという名前のzipファイルを作る

対象ファイルを正規表現で特定の拡張子にしただけ。

特定のディレクトリの全ファイルが入ったzipを作る

zip zipname /path/to/save/* 
  • /path/to/save/配下の全てのファイルを対象に
  • zipnameという名前のzipファイルを作る

対象ファイルを正規表現で特定のディレクトリにしただけ。
もちろん、拡張子とディレクトリを組み合わせて使える。

特定のファイル、パターンを除外してzipを作る

zip zipname * --exclude exclude.sh *.json
  • 現在のディレクトリ内の全てのファイルを対象に
  • exclude.shと拡張子がjsonのファイルを除外して
  • zipnameという名前のzipファイルを作る

--excludeの引数は複数指定できるし、正規表現も使える。

特定のディレクトリのzipを作る

zip -r zipname.zip directory/directory2
  • directory/directory2のディレクトリを対象に
  • zipnameという名前のzipファイルを作る

特定のファイル、パターンを除外して特定のディレクトリのzipを作る

zip -r zipname.zip directory/directory2 --exclude exclude.sh *.json
  • directory/directory2のディレクトリを対象に
  • exclude.shと拡張子がjsonのファイルを除外して
  • zipnameという名前のzipファイルを作る

上記と同じ--excludeオプションを使っただけ。

10
5
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
10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?