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.

I'm trying to back up files onto a server, but I'm having problems with files that have white spaces in the names.

I'm using this command in terminal:

FILES="testing/space\ in\ filename testing/and\ again"; rsync -v $FILES server::address

testing is the folder, with the two files being space in filename and and again.

When I run that, I get the following result:

rsync: link_stat "/home/user/testing/space\" failed: No such file or directory (2)
rsync: link_stat "/home/user/in\" failed: No such file or directory (2)
rsync: link_stat "/home/user/filename" failed: No such file or directory (2)
rsync: link_stat "/home/user/testing/and\" failed: No such file or directory (2)
rsync: link_stat "/home/user/again" failed: No such file or directory (2)

I've been looking into using the --protect-args option, but I haven't been able to get that working either.

share|improve this question

migrated from stackoverflow.com Sep 30 '11 at 8:47

This question came from our site for professional and enthusiast programmers.

    
Try quoting your $FILES variable: rsync -v "$FILES" (etc.) –  Kusalananda Sep 30 '11 at 20:48
add comment

1 Answer

You can temporarily change the IFS (internal field separator):

FILES="long filename with spaces
another one"
OLDIFS="$IFS"
IFS=$'\n'
rsync -v $FILES server::address
IFS="$OLDIFS" # restores default behaviour

Please note, that $'\n' is bashism. You might try this for other Posix shells:

IFS="
"

To process multiple files just separate them by your new IFS (in the above case a newline character). Instead of the newline character you might even use any characters you like.

share|improve this answer
    
Thanks so much! Really appreciate it :) –  Corbz Sep 29 '11 at 12:23
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.