Create a tar.gz File in a Single Command in Solaris

Solaris does not ship with the GNU tar and by default, the tar command in Solaris does not allow you to create gzip or bzip2 files, but only pure tarballs. You will need to create a tar file first and then compress the tarball with the gzip command.

But, we can use UNIX pipes and redirects to create a tar.gz file in a single command in Solaris. This is how we do it:

tar cf - foo | gzip -c > foo.tar.gz

We are trying to tar the foo file/directory, pipe the output to gzip, tell gzip to zip the contents from stdin and print the output to stdout and redirect the stdout to a file called foo.tar.gz!

To extract a tar.gz file in Solaris, run the commands in reverse order.

gunzip -c foo.tar.gz | tar xf -

We tell gunzip to extract foo.tar.gz to stdout, pipe the output to tar and instruct tar to extract the tarball from stdin.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }