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 the following problem. Normally one would use the command find exec cp -r to copy everything from one directory to another. In this case I am not allowed to do so, or use a while/for loop for the find command.

What I need it to do is copy everything from one directory to another with the complete directory structure.

share|improve this question

migrated from Dec 13 '12 at 14:00

This question came from our site for professional and enthusiast programmers.

Why do you need find for that? – Roman Newaza Dec 13 '12 at 8:19
Because my teacher told me so haha. But googling gives no results. – Mavix Dec 13 '12 at 8:24
You can use rsync -r – Roman Newaza Dec 13 '12 at 8:33
I know, but we may not use something different then find... – Mavix Dec 13 '12 at 8:45
you can use ls -R to list your directories recursively and pipe the result to a loop. – Roman Newaza Dec 13 '12 at 9:05
up vote 1 down vote accepted

You can start with something like this:

find -exec printf " echo {} | \
        sed 's|^$src|$dst|;s|/[^/]*$||' | \
        xargs -n1 -I@ mkdir -p @\n" \; | \

which creates the directory structure under destination directory. You can add many commands to printf.

share|improve this answer
i wish people did my homework for me when i was in school – Woot4Moo Dec 14 '12 at 0:51
this is far from complete though – perreal Dec 14 '12 at 0:56

You must log in to answer this question.