Copy between two different folders containing same sub-folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy between two different folders containing same sub-folders
# 1  
Old 03-05-2013
Copy between two different folders containing same sub-folders

I have a folder like this

Code:
ls input1

dir1 dir2 dir3 file1 file2 file3

dir1, dir2 and dir3 are sub-folders inside the folder input1

Code:
ls input2

dir1 dir2 dir3 file1 file2 file3

My dir1 in input1 folder has files f1, f2, f3 and f4.

My dir1 in input2 folder has file f4 and f5.

Now, I would like to have a bash script which checks the sub-folder names and updates the contents, but never replaces the entire contents.

If I would like to copy the contents of input2 to input1, then my dir1 sub-folder's contents in input1 should be f1, f2,f3,f4 and f5. But not just f4 and f5.

I could try cp, but my folders size is more than 500GB.

Any helps are highly appreciated. Thanks
# 2  
Old 03-05-2013
If you want input1 and input2 to always be the same, you could make input2 a symlink to input1.

If they must be kept separate for some reason and merged later -- if you're expecting bash to be faster than cp, that's kind of optimistic. Special-purpose utility optimized for this, vs a hand-written shell script?

Code:
cp -nr input2/* input1/

-n for no-clobber, it will not overwrite anything in input2.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-05-2013
Quote:
Originally Posted by Corona688
If you want input1 and input2 to always be the same, you could make input2 a symlink to input1.

If they must be kept separate for some reason and merged later -- if you're expecting bash to be faster than cp, that's kind of optimistic. Special-purpose utility optimized for this, vs a hand-written shell script?

Code:
cp -nr input2/* input1/

-n for no-clobber, it will not overwrite anything in input2.
Thanks Corona. I will try this.
# 4  
Old 03-05-2013
I don't think 'cp -r' really cares, it just walks the input tree and writes the output tree. You could walk both trees and make a new tree. Just make sure the input dir(s) are what you want in (not as) the output dir. While 'cp -r' will create the target if it is missing, but next time it will put all the files one level lower on the tree, so if the first time it creates dir1 with file1, the next time it will create dir1/dir1 and file1 in that. Ditto for scp, rcp and sometimes mv.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. UNIX for Beginners Questions & Answers

Rsync added new folders after copy?

Hi guys, Don't really know much about unix or anything, just starting to mess around a little bit to have more understanding in general. So, I tried using rsync to copy my macbook pro backup/clone from an external drive I have to another external drive. I ended up using... "sudo rsync -a... (1 Reply)
Discussion started by: cbjeebs
1 Replies

3. HP-UX

Recursive copy of Folders with files

Dear All, I will appreciate any help received. Our system is running on hpux v1 My problem is as follows: We have many customer folders with name fd000100, fd000101 and so on e.g. (Testrun)(testsqa):/>ll /TESTrun/fd000100 total 48 drwxrwx--- 2 fq000100 test 96 Jun 27 2004... (17 Replies)
Discussion started by: mhbd
17 Replies

4. Shell Programming and Scripting

Need to copy all but three folders

Hi, Below is the listing of folder "greece" $ cd greece $ ls tmp server logs properties I wish to copy all the contents of the dir "greece" to /tmp except the below three folders and its contents under "greece" 1.logs 2.server/bin/logs 3. server/cacheI am using sh (normal C... (4 Replies)
Discussion started by: mohtashims
4 Replies

5. Shell Programming and Scripting

Copy Folders and ZIP IT

HI All I have one master folder : ABCXYZ I have sub folder in there : AB XY AZ AC PR AL Now i want to copy AB , PR ,AL in to one new folder and zip it with time stamp. like Pre_02192013_12_32.zip Zip folder should be in master folder. (2 Replies)
Discussion started by: pareshkp
2 Replies

6. Shell Programming and Scripting

ftp script to copy folders recursively

hi all I want a script that will use ftp to copy folder and sub folders from source server to current server. if i use -r switch then it just copies folders for 5 level. (1 Reply)
Discussion started by: kashif.live
1 Replies

7. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

8. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

9. Shell Programming and Scripting

Copy file to two folders with condition

Hello! Please, help me write this simple script using bash scripting. Task: In Folder1 I have files: name1.txt, name2.txt, name3.txt .. etc In Folder2 may located such files: name1.txt, name2.txt .. etc In Folder3 may located files like: name1.txt_abc{some_symbols}_vxz,... (6 Replies)
Discussion started by: optik77
6 Replies

10. UNIX for Advanced & Expert Users

Copy Structure excluding some folders

Hi I want to copy the structure from one place to another. -> cd /hol/; -> find . -type d | cpio -pvdm /abc/cat; while copying the structure I want to exclude some directories like test1 and Test. I have read somewhere that this can be done with -prune option. Could anyone... (2 Replies)
Discussion started by: soumodeep123
2 Replies
Login or Register to Ask a Question