Scp a file with spaces or parentheses in the name

I have googled this so many times I thought I would put it down for myself. I found this great blurb on Tony Arkles blog.

Here’s a stupid unix trick: scp is an awesome tool for moving files around between unix-y machines (for instance, my Mac laptop and my Linux HTPC). Often enough, though, I need to copy a file with a space in the name, and this stumped me for a while.

Here’s the answer.  You need to quote it twice:

scp username@192.168.1.2:"'my file has spaces in it'" .

The first set of quotes protects the second set of quotes from the shell, so the file name gets passed over ssh with the quotes still in it… then the shell on the other end sees the quotes and removes them (preserving the spaces).

Leave a Reply

Your email address will not be published. Required fields are marked *