Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

scp

mv

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?

like image 677
Chris Maes Avatar asked Mar 20 '14 13:03

Chris Maes


2 Answers

An other solution, for launch in one time

scp /path/src/*.jpg user@host:/path/dst/ && rm /path/src/*.jpg
like image 77
openghost Avatar answered Sep 28 '22 06:09

openghost


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

rsync -avz --remove-source-files /local/dir/*.jpg user@ip:/remote/dir 
like image 42
Josh Jolly Avatar answered Sep 28 '22 06:09

Josh Jolly