rsync vs. cp

rsync -a /path/to/bar/ /path/to/foo/  # => /path/to/foo/[contents of bar]
rsync -a /path/to/bar /path/to/foo/   # => /path/to/foo/bar/[contents of bar]
 
cp -a /path/to/bar/ /path/to/foo/     # => /path/to/foo/bar
cp -a /path/to/bar /path/to/foo/      # => /path/to/foo/bar

why can’t cp have the same source behavior as rsync?

btw, I found the solution on this blog:

mkdir target_directory
cd source_directory
cp -a . target_directory

(on the blog, the author does cp -ap, but that looks redundant according to the man page)

Share:
  • del.icio.us
  • Reddit
  • Technorati
  • Twitter
  • Facebook
  • Google Bookmarks
  • HackerNews
  • PDF
  • RSS
This entry was posted in programming. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.