Handling spaces in filenames
labradley at mindspring.com
Wed Aug 12 12:02:16 MDT 2009
I'm a little unsure what you are telling me to do.
For the first 2 cases
FILE NAME WITH SPACES and "FILE NAME WITH SPACES"
it seems that you are telling me to quote all file names.
For the 3rd and 4th cases you seem to be saying
it is not necessary to quote FOLDER-NAME/ or FOLDER-NAME
which I would expect since there is no white space.
What do I do with directories with a space in them like
FOLDER NAME ?
The code I use _seems_ to be at variance with the directive to quote
file and directory names. Frankly, I don't see how rsync could tell
the difference between a subdirectory name and a file name as it moves
down the tree.
FWIW this is the code I use to back up the important subdirectories
on my Kubuntu Linux machine:
Syntax: rback / [-n]
# note: code ensures that $2 can only be '-n'
for SOURCE in /home/ /bin/ /dev/ /etc/ /lib/ /opt/ /public/ \
/root/ /sbin/ /usr/ /var/ ;
# example of an exclusion:
if [ $SOURCE = /home/ ]; then
rsync -uaHv $2 --delete $EXCLUDE $SOURCE $DEST$SOURCE
I can guarantee that SOURCE will have no spaces
meaning at the top of each subdirectory tree,
however there will be spaces in subdirectory and file names
as rsync proceeds down the tree.
So do I need to quote either $SOURCE and/or $DEST$SOURCE?
Tony Abernethy wrote:
> FILE NAME WITH SPACES -- this is 4 different space-separated parameters fed
> from the shell to the program
> "FILE NAME WITH SPACES" -- this is one parameter fed from the shell to the
> FOLDER-NAME/ -- this is one parameter and means all the files in the
> directory FOLDER-NAME/
> FOLDER-NAME -- this is one parameter and means the directory FOLDER-NAME/
> (and presumably taking all the contents with the directory)
> Unless the program does something special to parse out the spaces in the
> parameters, what you are seeing is normal behavior.
> I assume that the directory names with spaces are actually subdirectories of
> whatever you are backing up, ie those name you specify on the command line.
> You can also use wild-cards in addition to the names with spaces to give the
> illusion that it understands.
>> -----Original Message-----
>> From: rsync-bounces at lists.samba.org
>> [mailto:rsync-bounces at lists.samba.org] On Behalf Of Larry Alkoff
>> Sent: Tuesday, August 11, 2009 10:04 PM
>> To: Rsync
>> Subject: Handling spaces in filenames
>> Man rsync says that
>> "If you need to transfer a filename that contains whitespace,
>> you'll need to either escape the whitespace in a way that the remote
>> shell will understand, or use wildcards in place of the spaces.".
>> I am regularly doing backups with rsync and notice that files
>> names with
>> a space in them copy properly, without any special escape or other
>> Is this a change in rsync?
>> Is the warning in the man page no longer needed?
>> I will say that my 'filenames' with spaces are mostly (if not all)
>> directory names so perhaps rsync knows to handle directory
>> names better
>> than file names.
>> Can anyone enlighten me?
More information about the rsync