1

I am new to the world of Linux and in the process of setting up a Linux environment. I stumbled across the tar command as I need to view the contents of a file prior to extracting it and by accident ran the command tar tvf as opposed to tar tvfz. Is there any difference in running either command apart from the the fact that the z option is for gzip files?

2 Answers 2

2

As you are new to Linux then it seems appropriate to point you at the help system which is the man command.

As to your question it appears that tar is smart enough to realise that you have passed it a compressed archive and will process it appropriately even without the z switch.

tar -tvf suphp-0.7.1.tar.gz
drwxr-xr-x termi/termi       0 2009-03-14 18:08 suphp-0.7.1/
-rw-r--r-- termi/termi      13 2008-12-25 12:52 suphp-0.7.1/NEWS
-rw-r--r-- termi/termi    9416 2008-03-29 13:02 suphp-0.7.1/INSTAL
.
.
.

Note that if you use tvfz it will fail because a file has to follow the f switch

 tar -tvfz suphp-0.7.1.tar.gz
 tar: z: Cannot open: No such file or directory

so you should use tvzf

6
  • Iain - Thanks I did read the man pages however was unsure if running the inappropriate command would have repercussions Jul 12, 2011 at 20:23
  • @PeanutsMonkey: As you are running it in t test mode it's only reading the file anyway so won't damage it.
    – user9517
    Jul 12, 2011 at 20:32
  • Thanks. The article I am reading suggests that I run the command as tar tvfz - thegeekstuff.com/2010/04/unix-tar-command-examples Jul 12, 2011 at 20:42
  • @PeanutsMonkey: If that works with your tar then please let me know which verion it is. tar --version
    – user9517
    Jul 12, 2011 at 20:59
  • Iain - It is version 1.15.1. I am running the latest release of CentOS Jul 12, 2011 at 21:00
-1

There is no difference other than tar tvf will not be able to read a .tar.gz file, only a .tar file.

1
  • Please see my comment to Ignacio Vazquez-Abrams Jul 12, 2011 at 20:22

You must log in to answer this question.

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