Is it wrong to do tar czf somname.tar some_*_files instead of tar czf somname.tar.gz some_*_files, then of course tar xf somename.tar? That is : without adding the .gz extension.

This question is purely about not adding the .gz extension to the filename somename.tar and if this comes with any unexpected side-effects. This question is Not about the use of -z.

  • Try it on a single file. Does it work? Dec 19, 2022 at 19:34
  • 1
    You can give it pretty much any name, eg archive.box as long as you can remember what it means... Dec 19, 2022 at 19:42
  • @don_crissti I think the question related to the use of -z when creating the archive and the lack of it when attempting to extract files. I've suggested the OP simply tries it Dec 19, 2022 at 19:53
  • Yes, it does work. But I do worry that (when) breaking conventions might come with unexpected side-effects. Hence the question. Dec 19, 2022 at 19:54
  • 1
    I'd say it's bad form to have a ...tar.gz file without the .gz as it might be a tar --lzma file but ultimately tar can figure all that out on its own. Functionally it shouldn't matter.
    – SHawarden
    Dec 19, 2022 at 20:40

3 Answers 3


You can name the tarball anything you like. For example,

tar czvf surprise.c /etc/hosts 2>/dev/null

file surprise.c
surprise.c: gzip compressed data, from Unix, original size modulo 2^32 10240

You may find that a GUI expects such files to be suffixed with .tar.gz or .tgz, and if I were looking for a compressed tarball I'd expect it to have one of those two suffixes, but the system itself doesn't worry.

Conclusion? Use conventional suffixes to provide informational hints about the file contents. In the case of tar, use .tar for an uncompressed archive and either .tgz or .tar.gz for a gzip-compressed archive.

  • Beware that to name the tar ball -, you have to write it tar czf ./- files or tar cf - files | gzip > - as with tar czf - files, tar would interpret that - as meaning stdout. Dec 19, 2022 at 22:09

Omitting the .gz from the end of a filename does not prevent a tar cz command from writing the output file in compressed form, and it does not prevent most GNU tar x commands from automatically detecting the input file is compressed and de-compressing it. I.e., the computer doesn't need you to have the .gz on the end of the filename to know how to work with the file.

So your question boils down to how you communicate with other people about the contents of the file. They are the ones who might be confused by the lack of .gz on the filename and do the wrong thing with it. (sometimes, if months pass between creating the file and unpacking it, those "other people" can be you)

If it's important for other people to see the .gz. to know the file is compressed, then include it. If it's not very important, then you can omit it.


At least for GNU tar (which is the only tar I'm familiar with) as long as you specify the compression option I don't think the extensions matter when you are extracting with tar xf.
Let's omit the second extension (xz):

tar cJf archive.tar  pic*.jpg
file archive.tar
archive.tar: XZ compressed data, checksum CRC64

and the first one (tar):

tar cJf archive  pic*.jpg
file archive
archive: XZ compressed data, checksum CRC64

Let's use jpg extension:

tar cJf archive.jpg  pic*.jpg
file archive.jpg
archive.jpg: XZ compressed data, checksum CRC64

Let's use tar.gz extension but still compress with xz:

tar cJf archive.tar.gz  pic*.jpg
file archive.tar.gz 
archive.tar.gz: XZ compressed data, checksum CRC64

As you can see, in all cases, tar correctly archived and compressed the files (with xz), irrespective of the name of the archive. The extension does make a difference if you use --auto-compress... i.e. if you provide an extension that is supported, it will use the right compressor

tar caf archive.tar.xz  pic*.jpg
file archive.tar.xz
archive.tar.xz: XZ compressed data, checksum CRC64

whereas if it doesn't recognize the extension (or if you use tar) it will create an uncompressed tar archive:

tar caf archive.bag pic*.jpg
file archive.bag 
archive.bag: POSIX tar archive (GNU)

Regardless, in all cases, tar xf will extract the files, as the manual explains:

Reading compressed archive is even simpler: you don’t need to specify any additional options as GNU tar recognizes its format automatically. Thus, the following commands will list and extract the archive created in previous example:

# List the compressed archive
$ tar tf archive.tar.gz
# Extract the compressed archive
$ tar xf archive.tar.gz

The format recognition algorithm is based on signatures, a special byte sequences in the beginning of file, that are specific for certain compression formats...If this approach fails, tar falls back to using archive name suffix to determine its format (see auto-compress, for a list of recognized suffixes).

Is it good practice not using extensions? No. As other people have said, the main goal here is clarity.

  • FWIW, tar cf - a | gzip | xz | bzip2 | zstd > b; bsdtar tf b works fine. No need for file extension or telling it what decompressor to use. Dec 19, 2022 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .