how to copy all files from one location to another in linux

3

1

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

Jason

Posted 2011-05-04T03:48:07.840

Reputation: 1 619

Answers

3

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

Thomas

Posted 2011-05-04T03:48:07.840

Reputation: 2 232

This did not work for me. It still copied over the "www" folder. I followed the last example, and even left off trailing slashes – Nick Rolando – 2015-08-13T20:05:07.007

2

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

Kracekumar

Posted 2011-05-04T03:48:07.840

Reputation: 125

1

cp -pRiv /var/www/{*,.*} /media/magneto

and, dovetailing off Thomas' answer:

pushd /var/www; cp -R . /media/magneto; popd;

Brian Vandenberg

Posted 2011-05-04T03:48:07.840

Reputation: 504

Will this not ignore hidden files? – Jason – 2011-05-04T04:30:02.203

@Jason - There ya go. That should do it -- at least, it will work in bash, csh, and tcsh. – Brian Vandenberg – 2011-05-04T04:31:51.500

0

cp -R /var/www /media/magneto

This will copy www folder to /media/magneto folder
Use below cmd:

cp -R /var/www/* /media/magneto

This will copy all the files and folder to /media/magneto folder from www folder

MukulChakane

Posted 2011-05-04T03:48:07.840

Reputation: 1