Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can do every single step:
1, compress file using tar
2, copy to remote machine using scp
3, login remote machine using ssh, need password
4, uncompress the file
but, I want to write a single script to do the work, anyone suggestion?

share|improve this question
tar does not compress. It just puts multiple files together into one single file, but without any compression. You use e.g. gzip or bzip to compress a tar file. The tar command is still necessary though, because those compression algorithms can only operate on single files. – Byte Commander Jan 31 at 13:43
I use the -z flag to compress – haolly Feb 1 at 8:49

Why don't you use rsync to do that? From the computer were you want to get the file

rsync myuser@ myfile

will move the file over the two computers, taking care of the transportation. You can even pass recursively (-r) if you want to sync the whole directory.

Regarding compressing the data, you can obtain it via -z option, but keep in mind that if your connection is fast and your CPU is slow (mobile devices) you will have better performances just transferring the data without compressing them.


Following the comment below, I suggested to look into fabric (, which will give you the ability to operate on a server by remote.

so for example as a template you could:


from fabric.api import run

def kill_and_replace():
    run('killall myserverprocess')
    run('cp mynewfile myoldfile')


share|improve this answer
I'm sorry, I didn't said clearly, Acutally, it's not just sync files, I need login to remote machine to kill the server program, and then replace the files it needed, and then restart it, so it will be updated – haolly Feb 1 at 8:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.