Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 6
    -delete is much nicer than -exec rmdir {} + etc Commented Jul 14, 2016 at 6:11
  • 3
    I would skip the asterisk because and just have trailing slashes / with paths if doing this locally. If you use asterisk rsync will skip hidden files such as .htaccess or .htpasswd (if any) Commented Apr 15, 2019 at 11:52
  • 2
    You should execute the find command only if rsync exists successfully. Otherwise, you'll remove empty directories in the source that you might actually want to preserve. Use the ampersand operator, so: rsync ... && find ... Commented Dec 16, 2019 at 17:28
  • 2
    NB: if your /source is actually a symlink, find will not delete any empty folders after rsync is finished. You have to cd into /source and then run find . -type d -empty -delete Commented Sep 3, 2020 at 17:02
  • 2
    @dsz when you use -delete the -depth action is automatically enabled Commented Feb 3, 2022 at 23:52