[PLUG] Copying to new host, excluding a directory tree

Reid nrwahl at protonmail.com
Wed Jul 17 23:08:39 UTC 2019


The `--exclude` option might do what you need.

[root at fastvm-rhel-7-6-21 home_tmpdir]# ls -R
.:
file1  file2  file3  tmpdir

./tmpdir:
file4  file5  file6

[root at fastvm-rhel-7-6-21 home_tmpdir]# rsync -r --exclude=tmpdir . /tmp/tmpdir1

[root at fastvm-rhel-7-6-21 home_tmpdir]# rsync -r . /tmp/tmpdir2

[root at fastvm-rhel-7-6-21 home_tmpdir]# ls -R /tmp/tmpdir1
/tmp/tmpdir1:
file1  file2  file3

[root at fastvm-rhel-7-6-21 home_tmpdir]# ls -R /tmp/tmpdir2
/tmp/tmpdir2:
file1  file2  file3  tmpdir

/tmp/tmpdir2/tmpdir:
file4  file5  file6


However, this will also exclude any file names within the ~ directory structure that contain the string "data". You could use the find command instead to get all the subdirectories of ~ besides ~/data. I believe this command will work:

# rsync -r $(find ~ -maxdepth 1 ! -name "data") SRC DEST


Ben's exclude pattern doesn't work for me; it still pulls the data dir. The `--exclude` option pattern-matches against the file name (and  a directory name is a file name). It doesn't seem to pattern-match against the path.




Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, July 17, 2019 3:51 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:

> Copying directories from one desktop to another using rsync. The rsync man
> page shows how to specify directories and individual files, but I've not
> seen how to exclude a subdirectory.
>
> On the source host is a directory ~/data/. On the target host /home is on
> /dev/sda2 while data is a separate partition (/dev/sda3).
>
> What syntax allows me to copy all files but those in the source ~/data/
> subdirectory to ~/ on the target host?
>
> TIA,
>
> Rich
>
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug





More information about the PLUG mailing list