Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CentOS: Copy directory to another directory

I'm working with a CentOS server. I have a folder named test located in /home/server/folder/test. I need to copy the directory test to /home/server/. How can I do it?

like image 356
BaTmaN Avatar asked Jan 27 '13 17:01

BaTmaN


People also ask

How do I copy a directory to another directory in Linux?

Similarly, you can copy an entire directory to another directory using cp -r followed by the directory name that you want to copy and the name of the directory to where you want to copy the directory (e.g. cp -r directory-name-1 directory-name-2 ).

How do I copy a file from one directory to another in Centos?

To copy files to the current directory, use the command “cp source .” . For example, to copy file2 to the current directory type “ cp /root/file2 . “ To copy Directories, use the command cp –r .

How do I copy and paste in Centos?

Consider using keyboard shortcuts.Press Ctrl + C to copy the files. Go to the folder into which you want to copy the files. Press Ctrl + V to paste in the files.

How do you copy all the files from a directory to another directory?

The cp command also copies entire directories into other directories if you specify the -r or -R flags. You can also copy special-device files using the -R flag. Specifying -R causes the special files to be re-created under the new path name.


3 Answers

cp -r /home/server/folder/test /home/server/
like image 157
James McLaughlin Avatar answered Oct 19 '22 20:10

James McLaughlin


To copy all files, including hidden files use:

cp -r /home/server/folder/test/. /home/server/
like image 44
deltaag Avatar answered Oct 19 '22 18:10

deltaag


As I understand, you want to recursively copy test directory into /home/server/ path...

This can be done as:

-cp -rf /home/server/folder/test/* /home/server/

Hope this helps

like image 17
Rajeshwari Avatar answered Oct 19 '22 18:10

Rajeshwari