Results 1 to 5 of 5
Hi,
I want to copy the entire contents of a directory from one location to another. The source directory consists of a number of subdirectories in a tree like structure.
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-11-2012 #1Just Joined!
- Join Date
- Aug 2012
- Posts
- 10
Copying a directory
Hi,
I want to copy the entire contents of a directory from one location to another. The source directory consists of a number of subdirectories in a tree like structure.
The normal 'cp source destination' command only copies the contents that directly fall into the source directory and skips those in the subdirectories.
Is there any command that can automatically create the subdirectories at the destination and copy the files correspondingly from the source location (ie create a replica of the source directory at the destination location).
Could anyone help me with this?
Thanks.
- 10-11-2012 #2
Use -r option.
Code:cp -r <source> <destination>
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 10-11-2012 #3Just Joined!
- Join Date
- Aug 2012
- Posts
- 10
It worked out. Thanks a lot
- 10-11-2012 #4
Aye, 'cp -r ...' is the way to do this. The 'cp' tool is quite powerful in what it can do, take a look at its manual page - which you can see on your terminal by typing 'man cp'.
You might also want to investigate the use of 'cp -a <src> <dest>' which also copies all the file permissions and ownership of the files being copied. It produces a replica of the directory tree suitable as a backup, which may be more than you're trying to achieve.Linux user #126863 - see http://linuxcounter.net/
- 10-12-2012 #5Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,673
just as an FYI, if you're doing this copying of the same source dir to the same destination dir repeatedly, you can look into rsync, e.g.:
that will copy all the files and subdirs, along with their permission (like the "cp -a" above) from the source dir to the destination (creating the destination dir, if it does not already exist), but will have the added benefit of being more efficient on the subsequent runs, as it will only copy over new files and files that have changed in the source.Code:rsync -av /source/ /destination/
There are gazillions of options for rsync (see "man rsync") so you can customize your rsync commands heavily.


3Likes
Reply With Quote
