Reputation: 516
I have two root folders with the same structure like that :
How can I copy all files in 'Folder1' including files in subfolder of it to another destination name 'Folder2'.
'Folder2' have the same structure with 'Folder1' and all subfolder are already created in 'Folder2'.
Upvotes: 0
Views: 149
Reputation: 20703
A simple
cp -a /path/to/folder1/* /path/to/folder2
will do the trick. The command will check wether a sub folder of folder1
already exists in folder2
(create it if it doesn't), copy the files contained and recursively do that for any sub folders found.
See the cp man page for details (which you can also read locally on the shell by issuing man cp
).
Upvotes: 0
Reputation: 11365
Make use of rsync tool
Datasetup: Creating Folder1 and Folder2 with respective subdirs
:~/User> ls -laRt Folder1/
Folder1/:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f7
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f8
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub3
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub2
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub1
Folder1/sub3:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f5
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f6
Folder1/sub2:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f3
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f4
Folder1/sub1:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f1
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f2
:~/User> ls -laRt Folder2
drwxr-xr-x 2 test test 4096 2015-09-29 09:10 sub1
drwxr-xr-x 2 test test 4096 2015-09-29 09:10 sub2
drwxr-xr-x 2 test test 4096 2015-09-29 09:10 sub3
copy using rsync
:~/User> rsync -avh Folder1/ Folder2/
building file list ... done
./
f7
f8
sub1/
sub1/f1
sub1/f2
sub2/
sub2/f3
sub2/f4
sub3/
sub3/f5
sub3/f6
sent 537 bytes received 220 bytes 1.51K bytes/sec
total size is 0 speedup is 0.00
Verify
:~/User> ls -laRt Folder2
Folder2:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f7
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f8
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub3
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub2
drwxr-xr-x 2 test test 4096 2015-09-29 09:08 sub1
Folder2/sub3:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f5
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f6
Folder2/sub2:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f3
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f4
Folder2/sub1:
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f1
-rw-r--r-- 1 test test 0 2015-09-29 09:08 f2
Upvotes: 0