すべてのサブディレクトリに繰り返しファイルを追加する

すべてのサブディレクトリに繰り返しファイルを追加する

現在のディレクトリとすべてのサブディレクトリにファイルを再帰的に追加(またはタッチ)する方法は?

たとえば、
次のディレクトリツリーを回転させたいとします。

.
├── 1
│   ├── A
│   └── B
├── 2
│   └── A
└── 3
    ├── A
    └── B
        └── I   
9 directories, 0 files

入力する

.
├── 1
│   ├── A
│   │   └── file
│   ├── B
│   │   └── file
│   └── file
├── 2
│   ├── A
│   │   └── file
│   └── file
├── 3
│   ├── A
│   │   └── file
│   ├── B
│   │   ├── file
│   │   └── I
│   │       └── file
│   └── file
└── file

9 directories, 10 files

ベストアンサー1

どうですか?

find . -type d -exec cp file {} \;

からman find

   -type c
          File is of type c:
           d      directory

   -exec command ;
          Execute  command;  All following arguments to find are taken 
          to be arguments to the command until an  argument  consisting 
          of `;' is encountered.  The string `{}' is replaced by the 
          current file

したがって、上記のコマンドはすべてのディレクトリを検索し、cp file DIR_NAME/各ディレクトリで実行されます。

おすすめ記事