LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How make rsync deal with spaces in a directory name? (https://www.linuxquestions.org/questions/linux-software-2/how-make-rsync-deal-with-spaces-in-a-directory-name-4175665420/)

Pedroski 12-04-2019 05:31 PM

How make rsync deal with spaces in a directory name?
 
Thanks to help from linuxquestions, I can back up this laptop to another laptop using rsync. Works great and extremely quickly!

You probably know that old TV series 24. America is just full of bad guys, and they all want to get Jack Bauer! It's rubbish I know, but it relaxes me in the evening.

Yesterday, I wanted to copy a directory 24 Season6 from a usb to my old laptop. Thought I would use rsync, as I am very impressed with that program!

But I kept getting errors. I think it is because of the space in the directory name.

The usb is at /media/pedro/X3

I tried:

Quote:

rsync /media/pedro/X3/24 Season6 /home/pedro/24
but I kept getting a 'can't stat' error 'no such file or directory'

Is it the space causing the error?

uteck 12-04-2019 05:42 PM

you need to mark the space so bash knows it is there. In Linux, most Unix, that is done with the backslash \
So "24 Season6" on the command line is "24\ Season6"
Code:

rsync /media/pedro/X3/24\ Season6 /home/pedro/24

boughtonp 12-04-2019 06:09 PM

In addition to backslashes, you can also wrap the whole name in quotes. (Useful if a path would have lots of spaces.)

Also, for local paths you can use tab-completion - try typing...
Code:

/me<tab>/p<tab>/X3/24<tab>6
...and (depending on which other files/dirs exist), you may get the whole path with half as many key presses.

FlinchX 12-05-2019 12:00 AM

Quote:

Originally Posted by boughtonp (Post 6064752)
In addition to backslashes, you can also wrap the whole name in quotes.

Yes. And they better be single quotes. Because $foo inside double quotes will get interpreted as variable with name foo by shell.


All times are GMT -5. The time now is 12:32 PM.