0

I'm using Max OS X. I'm trying to copy all header files (.h) to specific directory (./aaa) from all subdirectories in source directory. (./src/) This command worked well.

cp ./src/*/*.h ./aaa

But I want to copy all header files in the subdirectories in all depths. Not only 1st depth. Is this possible and how to do this? I believe there is an elegant way to do this.

Eonil
  • 10,459
  • 16
  • 36
  • 54

2 Answers2

3
find /src -name '*.h' -print0 | xargs -0 cp --target-directory=./aaa

(Performs significantly better than -exec for large numbers of files)

Slartibartfast
  • 3,295
  • 18
  • 16
  • 1
    Or you could just use `-exec ... +`. – Ignacio Vazquez-Abrams Jun 23 '10 at 03:52
  • Perhaps. I grew up when that wasn't an option. I also object to silly quoting rules that seem to be in place for -exec commands. Finally, xargs is an excellent unix-y tool that everyone should be aware of. For example, it lets you do things like ensure that you have three processes running (each having 4 files to handle) at all times while you have the input to work with (taking advantage of mulitple CPUs for e.g. encoding audio files) – Slartibartfast Jun 24 '10 at 02:24
2
find ./src -name '*.h' -exec cp {} ./aaa \;
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84