Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Directory A and B have many subdirectories with nearly identical content. Directory B may have newer files and some subdirectories that directory A does not have. When files in Directory B are newer, I want those to overwrite the ones in A. When B contains subdirectories that A does not have, I want B directories to be merged into the results. So, I guess all I'm saying is I need to merge two directories using commands available on Solaris and OSX. I'm working locally on OSX, but will need to perform the same procedure on a Solaris box. I've found a couple of techniques. The first approach is to use tar:

cd A
tar -cvf content.tar *
cp content.tar ../B
tar -uvf content.tar *
cp content.tar ../
mv A A_backup; mv B B_backup
tar -xvf content.tar

(Wow! that seems messy)

Another approach:

cd B
tar cf - . |(cd ../A; tar xvf -)

(That merges everything into A)

The problem I have with both is perhaps mostly a confidence issue. I'm not familiar with the methods and can't really see what is happening. I can't see what files were overwritten or what folders or files existed in B that did not exist in A.

Is there a better way?

share|improve this question

migrated from Jun 1 '11 at 14:03

This question came from our site for professional and enthusiast programmers.

If you don't require using same tool on both systems, consider making this two questions. – Daniel Beck Jun 1 '11 at 14:07

Turns out rsync can be used for local directories.

rsync -av B A
share|improve this answer
Thanks, that will work well for OSX, but it isn't available to me on the Solaris system. – Michael Prescott May 31 '11 at 21:25

Mac OS X has ditto:

ditto [-v] [-V] [-X] [<options>] src ... dst_directory

In its first form, ditto copies one or more source files or directories to a destination directory. If the destination directory does not exist it will be created before the first source is copied. If the destination directory already exists then the source directories are merged with the previous contents of the destination.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .