Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a following directory structure for my code containing *.c ad *.h files and some configuration and build files generated by automake & autoconf I want to copy only the *.c and *.h files into new directory structure like this

testdir/
├── subtest1
│   └── subtest11
│       ├── test111.c
│       └── test111.h
└── subtest2
    └── test.c

newtestdir/ <--------------------- ONLY THIS DIRECTORY IS CHANGED !!
├── subtest1
│   └── subtest11
│       ├── test111.c
│       └── test111.h
└── subtest2
    └── test.c

Any hints as to how to do this on Linux ???

Thanks for the gr8 work of sharing knowledge !!

share|improve this question
up vote 2 down vote accepted
rsync -a -f"+ */" -f"+ *.[hc]" -f"- *" testdir newtestdir
share|improve this answer

rsync with use of --include can do this.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .