I had a folder of useless C programs for a project. When I was compressing it using tar, I kept using

tar -cvf c-project

and then realized I'm setting the flag for the file name and I'm giving none.

So I tried remove the flag f and set the command to tar -cv c-project assuming, the name of the tar file would become c-project.tgz.

However, this is what happened.

enter image description here

This behavior doesn't appear when gzip is used. That is the additonal z flag is added.

Any idea why this is happening? The contents seem to be the content of the C files. However, why are they "scrambled"?

2 Answers 2


If you don't specify an output file, then tar outputs to "standard out" by default, which is typically your screen. Since the contents of a tar file isn't directly human-readable, this will appear to be garbage on your screen. The "standard out" behavior is useful when you pipe tar's output to another program, like tar -cv foodir | gzip > foodir.tgz. A shorter way to accomplish the same is tar -czvf foodir.tgz foodir. tar is an old program, and its syntax is quirky for historical reasons, so you'll probably find that there are just patterns for doing common tasks that you just get used to.

  • If I saved the output on the screen to a text file and then used that information to create a tgz file and then extracted it, would I practically get the files again?
    – Torcellite
    Nov 17, 2013 at 16:21
  • Your terminal program most likely wouldn't save the exact raw contents, so that probably wouldn't work.
    – jjlin
    Nov 17, 2013 at 19:47

If you look with more attention you may notice that you wrote

tar -cvf c-project

It's equivalent to

tar -cvf c -p roject

O-O-O-ps... Indeed you try to create tar archive with name c and additional option p. Such option exist. So you don't get error p - unknown option. But you try to archive dir roject. This absent object. Unfortunately I can't see you screen short. You must just enquote "c-project". And the is no problem...

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.