stdin and stdout with tar

While archiving, we can specify stdout as the output file so another command in a pipe can read it as stdin and process the archive.

This technique will transfer data through a Secure Shell (SSH) connection, for example:

    $ tar cvf - files/ | ssh user@example.com "tar xv -C Documents/"

In the preceding example, the files/directory is added to a tar archive which is output to stdout (denoted by -) and extracted to the Documents folder on the remote system.

Get Linux Shell Scripting Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.