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

This question is very similar to this one except that I want to maintain the file's original subdirectories.

For example if I had


I'd want to copy all the text files to /temp2 so that the directory structure would look like:


Thanks for your help!!

share|improve this question
up vote 0 down vote accepted

If you want to replicate the whole directory structure, then simply do cp -a /temp /temp2 if /temp2 doesn't exist yet, or cd /temp; cp -a . /temp2 if the target directory already exists. (-a is a Linux-specific options to cp; on other systems you can use cp -Rp for a recursive copy preserving permissions.)

If you want to copy only certain files based on their names, use rsync. It has sophisticated include-exclude rules; I wrote a tutorial for these rules in response to a question asking how to do this at Unix Stack Exchange.

If you want to match files through other criteria such as the date, the simplest way is to combine rsync with zsh's pattern matching rules, as in Marcel Stimberg's answer to the above-mentioned question.

share|improve this answer
Great, thanks for your help! Especially the links, they were just what I needed! – evan Nov 18 '10 at 19:06

Without additional information, the best solution that I can suggest is:

cp -rp temp temp2
share|improve this answer

You must log in to answer this question.

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