Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.