ファイルフォルダフォルダがあります。すべてのファイルを親ファイルにコピーしようとしています。次のコマンドはdirname "{}"
findコマンドの前に実行されるため、機能しません。何ができますか?
find . -name "*" -type f | xargs -I "{}" cp "{}" `dirname "{}"`
ベストアンサー1
現在の作業ディレクトリからディレクトリツリーの下のすべてのファイルを各ファイルの親ディレクトリに移動するには、breakまたはを実行xargs
する必要さえありません。dirname
find
$ tree
.
+--- dir1
| +--- somefile
+--- dir2
| +--- someotherfile
$ find . -type f -execdir mv "{}" ../ \;
$ tree
.
+--- dir1
+--- dir2
+--- somefile
+--- someotherfile
execdir
forオプションは、find
一致する各ファイルを含むディレクトリで指定されたコマンドを実行します。