How to RSYNC a single file? How to RSYNC a single file? linux linux

How to RSYNC a single file?


You do it the same way as you would a directory, but you specify the full path to the filename as the source. In your example:

rsync -avz   --progress  /var/www/public_html/.htaccess root@<remote-ip>:/var/www/public_html/

As mentioned in the comments: since -a includes recurse, one little typo can make it kick off a full directory tree transfer, so a more fool-proof approach might to just use -vz, or replace it with -lptgoD.


Basic syntax

rsync options source destination

Example

rsync -az /var/www/public_html/filename root@<remote-ip>:/var/www/public_html

Read more


Michael Place's answer works great if, relative to the root directory for both the source and target, all of the directories in the file's path already exist.

But what if you want to sync a file with this source path:

/source-root/a/b/file

to a file with the following target path:

/target-root/a/b/file

and the directories a and b don't exist?

You need to run an rsync command like the following:

rsync -r --include="/a/" --include="/a/b/" --include="/a/b/file" --exclude="*" [source] [target]