LoginSignup
3
3

More than 5 years have passed since last update.

ディレクトリの中にあるディレクトリの zip アーカイブをそれぞれ別に作る

Last updated at Posted at 2015-10-01

要は、

somedir/
  +- dir01/
  |    +- ...
  +- dir02/
  |    +- ...
  +- dir03/
  |    +- ...
  :

みたいになっている状態のディレクトリから

somedir/
  +- dir01.zip
  +- dir01/
  |    +- ...
  +- dir02.zip
  +- dir02/
  |    +- ...
  +- dir03.zip
  +- dir03/
  |    +- ...
  :

こうしたいということです。
dir0{1,2,3}.zip を展開すると、それぞれ dir0{1,2,3} の中身が出てくるみたいな感じです。

find(1)zip(1) をつかってやっていきます。

$ find /path/to/somedir/ -maxdepth 1 -mindepth 1 -type d -exec zip -r {}.zip {} \;

カレントディレクトリで実行する場合は、単に以下のようにすればよいです:

$ find . -maxdepth 1 -mindepth 1 -type d -exec zip -r {}.zip {} \;

ターゲットとなるディレクトリ以下のディレクトリに対しても再帰的に zip が実行されないように -maxdepth 1 と指定し、somedir/ そのものが zip されないように -mindepth 1 と指定してあるところがミソです。

3
3
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
3
3