LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-17-2011, 06:03 PM   #1
mrwall-e
Member
 
Registered: Jul 2010
Distribution: Arch Linux, Xubuntu, Gentoo
Posts: 44

Rep: Reputation: 0
Merge directory trees


I have a couple directories in the following format:

+ Dir 1
----+ Dir A
-------- file1
----+ Dir B
-------- file2
+ Dir 2
----+ Dir A
-------- file3
----+ Dir C
-------- file2
+ Dir 3
----+ Dir B
-------- file2
----+ Dir C
-------- file1

My desired structure is:

+ Dir Final
----+ Dir A
-------- file1
-------- file3
----+ Dir B
-------- file2-1 [or something so that the two files don't overwrite]
-------- file2-2
----+ Dir C
-------- file2
-------- file1

Basically, I would like to combine all the directories that I can, without deleting/overwriting any files. I have looked at Rsync, but I could not find the correct options to do what I wanted.

Thanks

Last edited by mrwall-e; 02-17-2011 at 06:08 PM.
 
Old 02-19-2011, 07:27 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Just use cp.

Code:
mkdir dir_final

cp -R dir_1/* dir_final
cp -R dir_2/* dir_final
cp -R dir_3/* dir_final
 
Old 02-20-2011, 08:14 AM   #3
mrwall-e
Member
 
Registered: Jul 2010
Distribution: Arch Linux, Xubuntu, Gentoo
Posts: 44

Original Poster
Rep: Reputation: 0
Re: Merge directory trees

One of these directories is quite large. Would it work if I used it as the final directory? Because otherwise I don't think I have enough space.

Thanks
 
Old 02-20-2011, 08:22 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Sure.

If dir_1 is the large one, just do it like this:

Code:
cp -R dir2/* dir1
cp -R dir3/* dir1
I think you understand the concept. If a dir is copied to a place that already has a dir by the same name, the contents of the conflicting dir are not deleted.
 
Old 02-20-2011, 08:29 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Isn't one of the wishes the creation of a renamed duplicate if one is encountered?

Quote:
# in
+ Dir 1
----+ Dir B
-------- file2

+ Dir 3
----+ Dir B
-------- file2

# out
----+ Dir B
-------- file2-1 [or something so that the two files don't overwrite]
-------- file2-2
The cp -R solution will override duplicate files.......
 
Old 02-20-2011, 08:37 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by druuna View Post
Hi,

Isn't one of the wishes the creation of a renamed duplicate if one is encountered?



The cp -R solution will override duplicate files.......
I didn't notice that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mkisofs and preserving directory trees crontab Linux - Software 2 03-27-2009 10:00 AM
Compare directory trees on seperate servers ? dhg1848 Linux - Server 4 11-26-2008 08:47 AM
LXer: Protecting directory trees with gpgdir LXer Syndicated Linux News 0 04-25-2008 12:20 AM
Q: on deleting directory trees n00bJoe Arch 3 03-09-2006 12:13 PM
How to keep 2 directory trees synchronised? hrr Linux - General 2 07-02-2003 12:01 PM


All times are GMT -5. The time now is 06:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration