0

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.

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

1 Answer 1

1

You can start with something like this:

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

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

2
  • 1
    i wish people did my homework for me when i was in school Commented Dec 14, 2012 at 0:51
  • this is far from complete though Commented Dec 14, 2012 at 0:56

You must log in to answer this question.