Home > Linux > rsync – non recursive copying

rsync – non recursive copying

August 11th, 2009 Nick Leave a comment Go to comments

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”.

  1. Ben
    February 4th, 2011 at 01:18 | #1

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

  2. February 5th, 2011 at 16:02 | #2

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

  3. March 31st, 2011 at 09:33 | #3

    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
    May 25th, 2011 at 18:54 | #4

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

  1. No trackbacks yet.