Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So I currently do stuff like:

rm -rf ../../../$CLOUD_INSTALL_SUBDIR/lib_boost
mkdir ../../../$CLOUD_INSTALL_SUBDIR/lib_boost
cp -r ../../../$BOOST_ROOT_DIR/$BOOST_INSTALL_SUBDIR/lib/* ../../../$CLOUD_INSTALL_SUBDIR/lib_boost/

Which sucks... So I wonder how to update/remove/add only updated files between 2 folders (in demo we have the folder with the latest stuff ../../../$BOOST_ROOT_DIR/$BOOST_INSTALL_SUBDIR/lib/ and a folder with stuff that may be outdated ../../../$CLOUD_INSTALL_SUBDIR/lib_boost)?

share|improve this question

2 Answers 2

Rsync is your newest best friend.

rsync -av original/folder/ new/folder/

The trailing slashes are important on both; if you exclude the first, it will copy that folder as it's own folder into new/folder/. It's best to use the -a flag to preserve permissions, timestamps, etc.

Rsync will also automatically create directories as necessary to duplicate the structure.

share|improve this answer
    
Man, you were faster :) +1 –  Sergei Lomakov Jan 27 '12 at 4:42
    
Is rsync installed on most Linux unix distribs like rm or cd? –  myWallJSON Jan 27 '12 at 17:43
    
@myWallJSON Yes. While rsync isn't part of the absolutely minimal can't-even-boot-without-it core system like rm and cd, it's installed by default by most distributions, so you can expect it to be available on non-embedded Linux installations. –  Gilles Jan 27 '12 at 23:28
    
Rsync is marked ‘optional’ on Debian, i.e. not installed by default. I habitually (and explicitly) install it on every new box I deploy. However, it's marked ‘standard’ on Ubuntu. I wouldn't say you can expect it to be installed, I'd say your mileage may vary. –  Alexios Jan 28 '12 at 0:33
    
@laebshade: I'd also add -HAXS to rsync invocations unless you know for a fact there aren't hard links (-H), ACLs (-A), extended attributes (-X) or sparse files (-S). None of these are implied by -a. –  Alexios Jan 28 '12 at 0:38

You could use rsync for that, in your example it will like that:

rsync -va ../../../$CLOUD_INSTALL_SUBDIR/lib_boost/ ../../../$CLOUD_INSTALL_SUBDIR/lib_boost

Where -v option enables verbose mode and -a enables archive mode

You could read more about rsync on its manual page

share|improve this answer

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.