scp and decompress file at the same time without saving it

9,711

On target system (where the files will be extracted):

cd /target/dir && ssh user@source_server "cat /path/to/your/file.tar" | tar -xvv

OR

From source server (where the tar file is located):

ssh user@target_system "cd /target/dir && tar -xvv" < /path/to/your/file.tar

Below there are some alternatives to play with (on target system), just to show fancier ways you may find interesting.

scp and bash process substitution (if available):

scp user@source_server:/path/to/your/file.tar >(cd /target/dir && tar -x)

scp and /proc/self (if available):

cd /target/dir && scp user@source_server:/path/to/your/file.tar /proc/self/fd/1 | tar -x
Share:
9,711

Related videos on Youtube

scarlso9
Author by

scarlso9

Updated on September 18, 2022

Comments

  • scarlso9
    scarlso9 over 1 year

    I have been looking for an answer but nothing I have found has worked.

    There's a tar file that will be on a cd on a different server that I need to transfer over to my server and decompress it all at the same time without an intermediate save. the tar has multiple files, and they may be unknown.

    How can I do this either from my server or from the other server?

    I have explored this with scp, using tar and ssh, and tried to figure out with rsync..

    any help is appreciated

    • Kamil Maciorowski
      Kamil Maciorowski over 7 years
      tar is not a compressor, so you cannot decompress a tar file. You extract files from it.