LoginSignup
10
10

More than 5 years have passed since last update.

サブフォルダにある複数zipファイルのある特定のファイルだけを指定したフォルダにサブフォルダを作成せずに解凍(長っ

Posted at

タイトル長過ぎですね。下記のコマンドにたどり着くのに苦労しました。環境はMac OSX 10.9です。

find ./path/to/src -name '*.zip' | xargs -IX -n 1 unzip -j X -d ./path/to/dst \*.xml

ポイント

  • findの結果をxagrsに渡すところは、調べればたくさん出てくるので、それほど苦労は無いと思います。
  • findの結果をxargsで指定するコマンド(この例だとunzip)に1つずつ渡すのに-n 1を指定します。
  • 結果を渡す位置を指定するのに、-Iオプションを使います。Iに続いて任意の文字列(1文字でもいい)を書き、unzipの結果を渡す位置にもその文字列を書きます。(上の例だとXです)
  • unzipの解凍先を指定するのは-dオプションです。
  • -jは、サブフォルダを作らないオプションです。
  • zipファイル中の特定のファイルを指定する場合、ワイルドカードが使えますが、*はエスケープする必要があるらしく、\*としなければなりません。\を付けないと、no matches found: *.xmlの様なエラーになります。
10
10
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
10