I want to copy all the folders and files in the /var/www/ directory to another directory /media/magneto/

How do I do this?

I tried this command

cp -pRiv /var/www/ /media/magneto/

that didn't work because it basically created a directory called www underneath magento and started copying...

link|improve this question

58% accept rate
feedback

3 Answers

up vote 1 down vote accepted

Try

cp -R /var/www /media/magneto Avoid the extra forward slash at the end of the path name.

Or

you can navigate to the /var directory in terminal and then try

cp -R www /media/magneto

link|improve this answer
feedback

If the magneto directory exists, you can use the following command:

cp -R /var/www /media/magneto

If it doesn't already exist you can use the following command to create it:

rsync -av /var/www/ /media/magneto
link|improve this answer
feedback
cp -pRiv /var/www/{*,.*} /media/magneto

and, dovetailing off Thomas' answer:

pushd /var/www; cp -R . /media/magneto; popd;
link|improve this answer
Will this not ignore hidden files? – Jason May 4 '11 at 4:30
@Jason - There ya go. That should do it -- at least, it will work in bash, csh, and tcsh. – Brian Vandenberg May 4 '11 at 4:31
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.