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)?

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.

  • Man, you were faster :) +1 Jan 27, 2012 at 4:42
  • Is rsync installed on most Linux unix distribs like rm or cd?
    – myWallJSON
    Jan 27, 2012 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. Jan 27, 2012 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, 2012 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, 2012 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

You must log in to answer this question.

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