difference between tar -xzf and tar xjf ? How do we determine that what combination should be used in order to extract something(.tar)

13,900

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.

Share:
13,900
Maniraj
Author by

Maniraj

Technology Intern At Tapp Me

Updated on September 18, 2022

Comments

  • Maniraj
    Maniraj over 1 year

    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.

    • Rui F Ribeiro
      Rui F Ribeiro about 6 years
      I advise a question at a time. A good starting point is reading the man page of tar linux.die.net/man/1/tar . Having or not the "-" is for historical reasons, z is for gzipped and j is for bzipped tar(red) files.
    • Maniraj
      Maniraj about 6 years
      I read the same but wasnt able to get things . And what do you mean by "historical reasons"?
    • user4556274
      user4556274 about 6 years
      Partial duplicate: unix.stackexchange.com/questions/28403/tar-cvf-or-tar-cvf explains the optional hyphen.
  • Rui F Ribeiro
    Rui F Ribeiro about 6 years
    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.
  • Maniraj
    Maniraj about 6 years
    Still did not got how to form those combinations and how to deal with that "-" ??
  • user4556274
    user4556274 about 6 years
    @RuiFRibeiro, perhaps I can expand. I suspect this can be closed as a duplicate instead; I'm sure I've seen similar questions with the history of the different option formats already explained.
  • Rui F Ribeiro
    Rui F Ribeiro about 6 years
    @user4556274 Most probably, I noticed that too but have not searched. The OP is also asking too basic questions.
  • Rui F Ribeiro
    Rui F Ribeiro about 6 years
    Have my +1 too for the effort.
  • Knud Larsen
    Knud Larsen about 6 years
    user4556274 : »» Recent versions «« : Automatic recognition of .gz, .bz2 → tar version 1.15 - Sergey Poznyakoff, 2004-12-20 . Automatic recognition of .zx : Year 2009.
  • user4556274
    user4556274 about 6 years
    @KnudLarsen, thank you; updated answer to reflect your comment, with caveat about systems which have non-GNU versions of tar.
  • JoL
    JoL about 6 years
    @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"
  • yms
    yms almost 6 years
    For all those saying RT*M (or a variant of it): According to Google, this answer is a lot more helpful than 'man tar', it's the very first result when searching for "tar xjf".