I can use
rm to delete the old folder, then use
cp to copy the new folder. But how to do it in one go?
rsync -av --delete source/ target
This would delete all the contents of the directory
target that does not match the contents of the directory
source, and would additionally copy the contents of
/ at the end of
source/ is significant as without it, you would get a directory at
target/source instead of making
target a copy of
--archive) option makes
rsync copy timestamps and other metadata, and the
--verbose) option makes
rsync operate verbosely. Without
--delete, no existing contents in
target would be deleted (unless it had the same name as things in
source in which case it would be updated).
That is one go.
rm -fr olddir/* ; cp -a newdir/* olddir