要件
test[任意の文字列].txt
を満たすファイルを抽出し、別ディレクトリにコピーしたい
期待する動き(コピーの様子)
inputディレクトリに存在するtest[任意の文字列].txt
を、outputディレクトリにコピーする。
Before
.
├── input
│ ├── bar.txt
│ ├── hoge
│ │ ├── bar2.txt
│ │ ├── tes1.txt
│ │ ├── test3.txt
│ │ └── test4.txt
│ ├── test1.txt
│ └── test2.txt
└── output
After
.
├── input
│ ├── bar.txt
│ ├── hoge
│ │ ├── bar2.txt
│ │ ├── tes1.txt
│ │ ├── test3.txt
│ │ └── test4.txt
│ ├── test1.txt
│ └── test2.txt
└── output
├── hoge
│ ├── test3.txt
│ └── test4.txt
├── test1.txt
└── test2.txt
試したこと
コマンド
inputディレクトリで次のコマンドを実行する。
(カレントディレクトリ次第では想定外の動きをするため、絶対パスでディレクトリを指定するなど工夫したほうがいいかもしれない)
$ find ./ -type d | xargs -I{} mkdir -p ../output/{} && find -name "test*.txt" | xargs -t -I{} cp {} ../output/{}
コマンドの実行内容
- input以下のディレクトリ構造をoutputディレクトリにコピーする
(cpコマンドでは、存在しないディレクトリを作成して処理を続ける・・ということはできないため) - 条件を満たすファイルを指定ディレクトリにコピーする