Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
1  
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

Your Answer

 
discard

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