scp command line copy file to destination path with space.
今天準備用把一個文件拷貝到遠程電腦的移動硬盤上
遠程路徑是 /media/username/My Passport
注意“My Passport”帶了空格符,對於路徑來講屬於特殊符號。
嘗試一: 單引號
一開始拷貝的時候我用瞭如下命令
scp -r source_dir '[email protected]:/media/username/My Passport'
用了單引號,結果就出現錯誤
scp: ambiguous target
嘗試二:轉移符“\”
然後以爲單引號可能識別不了,就用轉移符“\”
scp -r source_dir [email protected]:/media/username/My\ Passport
結果還是出現錯誤
scp: ambiguous target
解決方案
後來通過linux論壇查找,終於找到方法,需要再路徑那裏加轉移符
scp -r source_dir [email protected]:"/media/username/My\\ Passport"
然後等待輸入密碼就可以了
大功告成
論壇地址:https://superuser.com/questions/1022976/scp-copy-has-error-ambiguous-target
scp myfile.txt [email protected]:"/file\\ path\\ with\\ spaces/myfile.txt"