Background
Have you ever needed to copy either a single file or a directory that contains spaces using scp? Here are a couple of techniques for how to do this.
Solution
Here are several ways to accomplish the same thing. Copying a entire directory with spaces and copying a file with spaces using scp.
1 2 3 4 5 6 7 |
# Ways to copy entire directories % scp -r user@myserver.com:'"/path/with/a/Space In It"' . % scp -r user@myserver.com:"'/path/with/a/Space In It'" . % scp -r user@myserver.com:'/path/with/a/Space\ In\ It' . % scp -r user@myserver.com:"/path/with/a/Space\ In\ It" . % scp -r user@myserver.com:/path/with/a/Space\\\ In\\\ It . % scp -r user@myserver.com:"\"/path/with/a/Space In It\"" . |
1 2 3 4 5 6 7 |
# Ways to copy a single file % scp -r user@myserver.com:'"/path/with/a/Space In It/file with spaces.txt"' . % scp -r user@myserver.com:"'/path/with/a/Space In It/file with spaces.txt'" . % scp -r user@myserver.com:'/path/with/a/Space\ In\ It/file with spaces.txt' . % scp -r user@myserver.com:"/path/with/a/Space\ In\ It/file\ with\ spaces.txt" . % scp -r user@myserver.com:/path/with/a/Space\\\ In\\\ It/file\\\ with\\\ spaces.txt . % scp user@myserver.com:"\"/path/with/a/Space In It/file with spaces.txt\"" . |
links
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.