LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-06-2015, 08:37 AM   #1
mr_si
Member
 
Registered: Nov 2006
Distribution: Server: Centos 6.6, Desktop: OpenSUSE 12.3
Posts: 34

Rep: Reputation: 4
Rsync with Ampersands in file names


Hi all,

So I'm in charge of the IT here at work and last night hit a problem which I've not come across before.

I rsync over ssh from work servers to off-site servers, which usually is fine but occasionally the files are so large that our upload internet speeds cannot handle it and I have to take a copy over to the remote site and sync them up "locally" (it's in a very convenient place so not a problem).

Anyway, I had the issue where I have a source folder in my home directory called:

"subfolder2"

which I wanted to copy in to:

"/directoryA/folder1/folder2/A & B Builders/subfolder"

on the destination server.


My only method was to rsync this over ssh by push method from my local media to the server but it didn't like the ampersand in the destination folder, so it ignored everything after the ampersand and so it wrote everything to a new directory on the destination server called:

"/directoryA/folder1/folder2/A"

The command I used at a bash command prompt was:

Code:
rsync -avh -e "ssh -p 22221" '/home/user1/subfolder2/' 'user@destinationserver:/directoryA/folder1/folder2/A && B Builders/subfolder'
You can see I used a double ampersand, which is what I thought was supposed to be done but it didn't work.

It listed out the files etc at it was sync'ing but it was only by luck that I found where it had sent them.

So, my question is as follows:

Is there a way of Bash not seeing the Ampersand in the file name and thinking it's a command?
I think the term is "escaping out" but I'm not sure and my searching on google hasn't helped me so far.
 
Old 11-06-2015, 08:51 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by mr_si View Post
Is there a way of Bash not seeing the Ampersand in the file name and thinking it's a command?
I think the term is "escaping out" but I'm not sure and my searching on google hasn't helped me so far.
When you put quotes around the filename (double or single quotes, both work in this case), ampersands lose their special meaning. You did the right thing, except you shouldn't have doubled the ampersand.

The term is usually "quoting". To quote a single character, use the backslash; e.g., that filename would be
Code:
/directoryA/folder1/folder2/A\ \&\ B\ Builders/subfolder
Quotes are probably easier to read in this case.

Last edited by berndbausch; 11-06-2015 at 08:53 AM.
 
1 members found this post helpful.
Old 11-06-2015, 09:59 AM   #3
mr_si
Member
 
Registered: Nov 2006
Distribution: Server: Centos 6.6, Desktop: OpenSUSE 12.3
Posts: 34

Original Poster
Rep: Reputation: 4
Thank you ever so much @berndbausch, that's very very useful to know.

Kind Regards,
Simon
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] samba/rsync file names! timl Linux - Software 2 06-15-2015 03:50 AM
[SOLVED] HowTo? Make rsync copy file names but not contents haertig Linux - Software 2 07-12-2014 04:05 PM
Bash: bash file names are different than openbox trash file names whatthefunk Programming 4 02-15-2011 01:52 AM
[SOLVED] How to changing same file names by their directory names? bayaraa_u Linux - General 3 04-09-2010 08:26 AM
php+XML - escaped ampersands not escaping correctly veritas Programming 7 06-22-2007 05:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration