Rsync file to file without specifying the parent folder as a destination?

Hello,
i see the way to copy the file using rsync is to specify the destination folder.
But how can i please copy using rsync while the destination is not folder but the full path to file?

var=/path2/file
rsync -av /path1/file $var

Hi Postcd,

You can do that just as you described, just tested it.

First, I used environment variable for the source to sync:

$ SRC=/tmp/test2.file
$ rsync "$SRC" /tmp/dest/testfile3

And the file is there with the given name:

$ ls dest/
testfile3

Next I used variable to source and destination as well:

DEST=/tmp/dest/testfile4
$ rsync "$SRC" "$DEST"

So it works well both ways:

$ ls dest/
testfile3  testfile4

Tested on Ubuntu 18.04, with rsync version 3.1.2.

1 Like

postcd, you’ve been using rsync for years. Read the man page yet?