1

While extracting a file with extension .gz we used tar -xzf and while extracting a file with extension .bz2 we used -xjf. What's the difference between these?

Sometimes the combination used is -tf, -xf etc and many more. How to determine which combination should be used with which kind of file? It maybe a basic question but I need an explanation regarding the same.

13

The generic answer for "how to determine" is to read the manual page for tar by issuing the command man tar on your system. (The linked page is a manual page for tar, but by issuing the command on your system you'll ensure you have the manual page for the version you are currently using.)

From the manual page you'll see that the z option causes the file(s) to be filtered through gzip, which by convention have the extension .tar.gz or .tgz, while the j option causes the file to be filtered through bzip2.

Versions of GNU tar since 1.15 (2004-12-21) autodetect common compression methods, so neither the j nor the z will be necessary on linux distributions of the last decade or so. tar xf ... will untar a file whether it is an uncompressed archive, a gzip-compressed archive, a bzip2-compressed archive, or several other formats. Other unix or unix-like systems (or linux distributions which don't use GNU tools ?) may not have this shortcut available.


As to the secondary question, the t option request only listing the files in the archive, while the x option actually extracts the files.

  • Would you please add the context of that question of "-"/historical reasons - BSD vs Sys V? tar should be one of the most ancient utilities around the block I suspect. – Rui F Ribeiro Feb 28 '18 at 12:46
  • 1
    @user4556274 Most probably, I noticed that too but have not searched. The OP is also asking too basic questions. – Rui F Ribeiro Feb 28 '18 at 12:49
  • 1
    @Maniraj You have got to experiment and read a lot about it. Only asking here wont cut it. – Rui F Ribeiro Feb 28 '18 at 12:50
  • 1
    user4556274 : »» Recent versions «« : Automatic recognition of .gz, .bz2 → tar version 1.15 - Sergey Poznyakoff, 2004-12-20 . Automatic recognition of .zx : Year 2009. – Knud Larsen Feb 28 '18 at 13:59
  • 1
    @Maniraj You know, ideally this site should be for questions not easily researched. In this case, to learn how to deal with the -, you can follow the link given to you: "GNU tar" > "Documentation for Tar" > "HTML" (any is good) > "Invoking GNU tar" > "The Three Option Styles" > "Old Option Style" – JoL Feb 28 '18 at 16:34

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.