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?
Asked
Active
Viewed 2.3e+01k times
5 Answers
106
cp -r /home/server/folder/test /home/server/

James M
- 18,506
- 3
- 48
- 56
-
3if i need to copy Only all files in `test` directory(without test directory) to `/home/server/`. how to ? – BaTmaN Jan 27 '13 at 18:06
-
20`cp -r /home/server/folder/test/* /home/server/` – James M Jan 27 '13 at 18:27
-
is there any difference in using -R in here ? – mahen3d Jun 01 '15 at 05:32
-
If there's a directory inside `test` directory, yes there is a difference. – John Smith Feb 01 '17 at 04:11
26
To copy all files, including hidden files use:
cp -r /home/server/folder/test/. /home/server/
-
4Thanks for this. Copying files no problem, copying files and hidden files was an elusive problem. +1 – Nate Sep 04 '15 at 23:17
-
1
-
In my case, in order to save time, I specify the current directory like this: `$ cp -r ./Origin/. ./Destination/` – Pathros Mar 13 '19 at 23:07
17
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

jmingov
- 13,553
- 2
- 34
- 37

Rajeshwari
- 171
- 1
- 4
-
Doesn't work for me. "No such file or directory" when adding the `*`. – user2924019 Feb 08 '17 at 20:05
1
For copy directory use following command
cp -r source Destination
For example
cp -r /home/hasan /opt
For copy file use command without -r
cp /home/file /home/hasan/

Hasan Barary
- 812
- 8
- 8