Other than by renaming the files first, how can I rsync
files that may have colons in their names?
1 Answer
Colons are only special in the first directory component of a command line argument. So if you have what looks like a relative path, prepend ./
.
$ mkdir sou:rce
$ rsync -a sou:rce/ de:st/
The source and destination cannot both be remote.
$ rsync -av ./sou:rce/ ./de:st/
sending incremental file list
created directory ./de:st
./
In a script:
case $source in
/*) :;;
*) source=./$source;;
esac
case $dest in
/*) :;;
*) dest=./$dest;;
esac
rsync "$source" "$dest"
-
Thank you, Guilles. The problem happens when I rsync from a hard drive to a flash memory stick:
rsync: mkstemp "/media/verd/rence/.Using an expressive work: fact or fiction.pdf.RbjlKK" failed: Invalid argument (22) rsync: mkstemp "/media/verd/rence/.What's in a concept: structural foundations for semantic networks.pdf.tLXoZz" failed: Invalid argument (22)
Commented Apr 20, 2011 at 18:36 -
3@Kejia柯嘉: Ah, ok, your problem is to rename-and-rsync, not to pass the colons to rsync. This question came up before on the Ubuntu site: How can I substitute colons when I rsync on a USB key? Unfortunately no one's produced a satisfying answer. Commented Apr 20, 2011 at 18:46
-
@Gilles'SO-stopbeingevil' How does rsync know, with
rsync src ./[email protected]:/test/
, if the dest is SSH or local? Here it could be both. Your answer states that prepending./
makes rsync be sure it's a local path. But it's not 100% sure:./hello
is a valid Linux username (I just tried withuseradd
). TL;DR: how to rsync with a remote with username./hello
, hostb.com
, and path/test/
?– BasjCommented Nov 24, 2020 at 15:17 -
@Basj I don't think rsync supports user names containing
/
. If you're using SSH for transport, I think you can use anssh_config
Host
block with aUser
directive. Note that rsync is likely not the only program that doesn't support/
in user names. POSIX only allows ASCII letters, digits and-_.
. Debianadduser
only allows this and@
(which surprises me because a lot of programs don't support@
in user names!). Commented Nov 24, 2020 at 15:43 -
@Gilles'SO-stopbeingevil' It would make sense indeed.
adduser a/b
givesadduser: To avoid problems, the username should consist only of letters, digits, underscores, periods, at signs and dashes, and not start with a dash (as defined by IEEE Std 1003.1-2001). For compatibility with Samba machine accounts $ is also supported at the end of the username.
. I should have tried this first instead ofuseradd
!– BasjCommented Nov 24, 2020 at 15:52
dir/
and notdir/*
in rsync arguments.rsync: mkstemp "/media/verd/rence/.Using an expressive work: fact or fiction.pdf.RbjlKK" failed: Invalid argument (22) rsync: mkstemp "/media/verd/rence/.What's in a concept: structural foundations for semantic networks.pdf.tLXoZz" failed: Invalid argument (22)
:
in the first place