User Tools

Site Tools


rsync_notes

top level separation

Situation:
I have a directory (say source/) with many sub directories and files under it (source/dir1, source/dir2, … , source/file1, source/file2, …). I want to copy it to two separate folders (say destA, destB). The first folder contains all the top level files (source/file1, source/file2 etc.,), the second folder contains the rest (source/dir1, source/dir2 etc., but not source/file1, or source/file2 etc.,).

Solution: There are two approaches I can think of. Both work. I prefer the second one as it is a bit cleaner.

Approach1:

rsync -prltvzD -n --delete-after --exclude='/*/' source/ destA/
rsync -prltvzD -n --delete-after --include='/*/' --exclude='/*' source/ destB

Approach2:

rsync -prltvzD -n --delete-after --exclude='*/' source/ destA/
rsync -prltvzD -n --delete-after --include='*/' --exclude='/*' source/ destB

In both approaches, the destA and destB directories will be created on the fly if necessary.

miscellaneous

tags | include all sub directories but exclude top level files, exclude top level directory, exclude all subdirectories

rsync_notes.txt · Last modified: 2021/05/25 12:55 by admin