I have a file in which i wanted to zip up and at the same time transfer over to another host using scp.

I tried to do the following command but failed. I do not mind zipping up and scp over later, but i just want to know where did I got it wrong

Am i wrong to use a pipe | over here ?

-bash-3.2$ gzip -c aum.dmp | scp oracle@
Usage: scp [-pqrvBC46] [-F config] [-S program] [-P port]
           [-c cipher] [-i identity] [-o option]
       [[user@]host1:]file1 [...] [[user@]host2:]file2

Regards, Noob

  • if you specifically know the file name beforehand (and do not need to automate this), then you better skip the pipe and make sure to wait for gzip to (successfully) finish: gzip -c file.dmp && scp file.dmp.gy user@host:/path/to/file. Note that your command is missing the source file for the whole copying action.
    – FelixJN
    Jul 28 '15 at 8:23

gzip will write to STDOUT, and scp can't handle it.


gzip -c aum.dmp | ssh -l  oracle 'cat > /export/home/oracle/aum.dmp.gz'



  • gzip -c aum.dmp | will gzip aum.dmp, and send result to stdout
  • ssh -l oracle will connect to user oracle on
  • 'cat > /export/home/oracle/aum.dmp.gz' will execute this command

'cat > /export/home/oracle/aum.dmp.gz'

  • cat will capture stdin (stdout from command before | )
  • > /export/home/oracle/aum.dmp.gz will write to this /export/home/oracle/aum.dmp.gz

the whole purpose of cat part, executed n remote site is to capture gzip result.

  • sorry for the late reply, i do not understand the last portion of the whole command , what does the ' ' meant ? so instead of scp, are we using ssh instead then ?
    – Noob
    Jul 30 '15 at 13:59
  • yes, scp can't handle STDIN/STDOUT but ssh can.
    – Archemar
    Aug 29 '16 at 7:17

In case you need to get the files/directories from a remote server, into a local archive, you can use tar + gzip inside ssh, and redirect to a local file. For example:

ssh user@server "sudo tar cvzf - /var/log/containers/**/*.log" > containers_logs.tgz


  • c - create archive file.
  • v - show the progress.
  • z - compress with gzip.
  • f - filename of archive.

You can use the -C flag to enable compression in scp transfer. This should be enough, although you can check man scp for more details on compression.

  • this will compress data on network, saving bandwith, it will not compress file.
    – Archemar
    Jul 30 '15 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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