本文介绍了是否有mv命令的scp变体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,该脚本会将文件从本地系统移动到远程系统.它必须通过像ssh这样的加密通道来执行此操作.做这个的最好方式是什么?我可以分两个步骤执行此操作:

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

但是,这不是原子过程(例如mv用于本地文件系统).如果副本失败,我也将不再拥有本地副本.如何编写脚本以确保仅在复制成功后才删除本地文件?

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?

推荐答案

您可以将rsync--remove-source-files结合使用:

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

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

这篇关于是否有mv命令的scp变体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:58
查看更多