rsync – non recursive copying

I was looking for a way to get rsync to copy all the files in a particular directory and not recurse into the sub-directories.   Unfortunately I couldn’t find an appropriate parameter and a quick search on Google turned up nothing (apart from a lot of other people asking the same question!)

So as a last resort I decided to use my brain, and I came up with a simple solution that works.   It’s of the form:

rsync -avc --exclude "*/" ./source/* ./destination/

The above will copy all the files from the directory called “source” into the directory “destination” and will not recurse into any subdirectories of “source”.

This entry was posted in Linux and tagged , , , , . Bookmark the permalink.

11 Responses to rsync – non recursive copying

  1. Ben says:

    A year and a half later and your tip kept me from spinning my wheels for at least two hours. Thank you!

  2. Nick says:

    Thanks for the comment – it’s nice to know it was useful for at least someone!

  3. Joe Auty says:

    This was also very helpful for me, although I’m guilty of tire spinning :) The rsync -d flag sounds like it ought to do this, but not so… Your solution above works perfectly! :)

  4. Adam says:

    Yes! Thanks very much for this little note :-)

  5. madgagnon says:

    This just saved my afternoon, thanks a bunch!

  6. Kevin says:

    Still useful. Needed this to sync just the top-level directory of a client site since the site has tons of large content on it, and I didn’t want all that coming right away.

    Of course then I synced the rest with plenty of –exclude flags, so one wonders why I bothered. But it worked nonetheless.

  7. John Resig says:

    Thank you!

  8. John Johnson says:

    FIVE years later, and it’s still the best answer I could find.

  9. Nick says:

    Thanks for the feedback everyone – most appreciated!

  10. EP says:

    August 2015 and still useful!

  11. RichardH says:

    Thanks for the tip! I found a cleaner option…
    rsync -avc –no-r ./source/* ./destination/

    This disables the -r implied by the -a option.

Leave a Reply

Your email address will not be published. Required fields are marked *