Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Other than by renaming the files first, how can I rsync files that may have colons in their names?

share|improve this question
    
Make sure you are using dir/ and not dir/* in rsync arguments. –  grawity Apr 19 '11 at 20:19
    
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) –  xando Apr 20 '11 at 18:40
add comment

1 Answer

up vote 3 down vote accepted

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"
share|improve this answer
    
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) –  xando Apr 20 '11 at 18:36
1  
@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. –  Gilles Apr 20 '11 at 18:46
    
Thank you, Guilles :-) –  xando Apr 20 '11 at 18:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.