tar syntax help

I am using AIX unix system.
I see the below snippet in one of our code.
Can you please advise what the tar - . and compress - >  means in the below code.

cd /home/testdir
tar -cpf - . | compress - > $filename

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

"-c" means "tar shall create an archive"
"-f -" means "tar shall write the archive to stdout"
"-p" means: "tar shall preserve permissions"
"." means "tar shall archive the current directory and everything below it"

So the "tar" part archives all that's in the current directory and below and writes the archive to stdout.

This output is then fed to the "compress" command by means of a pipe "|".

"-" means "compress shall read the data which should be compressed from stdin and write the compressed data to stdout".
Writing to stdout is the default whenever the input comes from stdin. The "official" flag  "-c" must be used when input comes from a file but the output should go to stdout nevertheless. Here "-" works (and could as well be omitted), because the input comes from stdin anyway.

So the "compress" part takes the archive created by tar from stdin, compresses it and writes the compressed data to stdout.


"> $filename" means "write the result to the file specified by the variable $filename".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
By the way, magento, I know you aren't asking about this, but "compress" is a very old type of compression, so if you're in a position to change it and are wanting a higher compression ratio, you could use gzip instead of compress.  Depending on your version of tar (also try gtar), you may be able to write it this way:
    filename=test.tgz     # or could call the tar file "test.tar.gz" for long
    cd /home/testdir
    tar -zcpf $filename .   # Note the '.' at the end

And for even better compression (at the cost of more CPU), you could use bzip2, and again, depending on your version of tar you may be able to write it this way:
    filename=test.tbz     # or could call the tar file "test.tar.bz2" for long
    cd /home/testdir
    tar -jcpf $filename .   # Note the '.' at the end

If those don't work, then maybe your version of tar/gtar doesn't support the -z (gzip) or -j (bzip2) flags, so you could use almost the same syntax you currently have, changing "compress" to "gzip" or "bzip2" and maybe changing a flag or two.
@tel2, please remember it's AIX!

"tar" as shipped with the OS does neither support "-z" nor "-j", and "gzip" as well as "bzip2" must be installed first, either from the so-called "toolbox" CD or from some third party provider, where "perzl.org" is by far the best (and free) resource. GNU tar can be obtained there, too.

gzip:   http://www.perzl.org/aix/index.php?n=Main.Gzip
bzip2: http://www.perzl.org/aix/index.php?n=Main.Bzip2
tar:      http://www.perzl.org/aix/index.php?n=Main.Tar
Yes, woolmilkporc, I remembered it is AIX, but I don't know whether extras like gtar or gzip have been installed in magento's environment...yet.

Apart from that, I'm not up-to-date with what recent AIX tar versions can do, but 15 years ago I needed to install gtar on AIX 3 to use '-z', which is why I said "(also try gtar)".
magentoAuthor Commented:
Thanks for all your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.