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

On Linux, I have directory #1, for example:

/foo/file (edited)
/foo/bar/foo/file6 (edited)

And directory #2, which may contain some of the same files:

/foo/file
/foo/file2
/foo/bar/file3
/foo/bar/file4
/foo/bar/foo/file5
/foo/bar/foo/file6

I'd like to move directory #1's files into directory #2 and if they exist, overwrite them. So we'd end up with:

/foo/file (edited)
/foo/file2
/foo/bar/file3
/foo/bar/file4
/foo/bar/foo/file5
/foo/bar/foo/file6 (edited)

(edited) denotes that the file is newer.

share|improve this question

migrated from stackoverflow.com Jul 27 '12 at 11:34

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

up vote 3 down vote accepted

There are a few ways I can think of:

cd /directory/one && tar cf - . | (cd /directory/two && tar xf - )

or

rsync -av /directory/one /directory/two
share|improve this answer
    
Since they mentioned Linux, you can assume gnu tar, which has -C for 'chdir': tar -C /directory/one -cf - . | tar -C /directory/two -xvf - – Rich Homolka Sep 14 '12 at 20:25

You must log in to answer this question.

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