Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted
find ./src -name '*.h' -exec cp {} ./aaa \;
share|improve this answer
find /src -name '*.h' -print0 | xargs -0 cp --target-directory=./aaa

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

share|improve this answer
1  
Or you could just use -exec ... +. –  Ignacio Vazquez-Abrams Jun 23 '10 at 3: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 2:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.