Is there an scp variant of mv command? [closed]

孤街浪徒 提交于 2020-03-14 07:34:45

问题


I am writing a script that will move files from a local system to a remote system. It must do so through an encrypted channel like ssh. What is the best way to do this? I can perform this in two steps like:

scp *.jpg user@ip:
rm *.jpg

But, that is not an atomic process (like mv is for a local filesystem). If the copy fails I will no longer have the local copies either. How can I script this to make sure the local files only get removed if the copy succeeds?


回答1:


You could use rsync with --remove-source-files:

rsync -avz --remove-source-files /local/dir/*.jpg user@ip:/remote/dir 



回答2:


An other solution, for launch in one time

scp /path/src/*.jpg user@host:/path/dst/ && rm /path/src/*.jpg


来源:https://stackoverflow.com/questions/22534309/is-there-an-scp-variant-of-mv-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!