I'm trying to copy the contents of a series of directories non-recursively to another remote system.
/dirA/dir1/file
/dirA/dir2/file
/dirA/dir3/file
dir1, dir2, and dir3 contain many directories that I do not want copied. Copy on the remote host to /dirB maintaining the same directory structure.
I tried:
rsync /dirA/*/ host:/dirB/
rsync /dirA/ host:/dirB/
But they don't do what I want.
Best Answer
rsync allows you to specify patterns that trigger the inclusion or exclusion of files and directories. I think you want to use something like this:
Explanation:
-a
triggers the archive mode that activates both recursion and preservation of "symbolic links, devices, attributes, permissions, ownerships, etc.", according toman rsync
.-f
is short for--filter=
, which adds a file-filtering rule.-
means this is an exclude pattern./
means the pattern must start atdirA/
(the rsync "transfer-root").*/*
part of the pattern refers to anything inside of a subdirectory./
limits the exclusion to directories. Files inside a subdirectory ofdirA/
are not affected.So in the end, rsync copies nothing more than one level down (and also does not create second-level directories).