Advertisement
cipherhawk

list-the-contents-of-a-tar-or-targz-file

Apr 3rd, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. src:https://www.cyberciti.biz/faq/list-the-contents-of-a-tar-or-targz-file/
  2. ---------------------------------------------------------------------------
  3.  
  4. List the contents of a tar or tar.gz file
  5. last updated December 21, 2018 in Categories BASH Shell, FreeBSD, HP-UX Unix, Linux, Solaris-Unix, Ubuntu Linux, UNIX
  6. How do I list the contents of a tar or tar.gz file on a Linux, OS X, and Unix-like system? How do I view contents of tar file without extracting it on Linux? How can I list contents of tar file on Unix?
  7.  
  8. GNU/tar or BSD/tar is an archiving program designed to store and extract files from an archive file known as a tarfile. You can create a tar file or compressed tar file tar. However, sometimes you need to list the contents of tar or tar.gz file on screen before extracting all files.
  9. Adblock detected 😱
  10. My website is made possible by displaying online advertisements to my visitors. I get it! Ads are annoying but they help keep this website running. It is hard to keep the site running and producing new content when so many people block ads. Please consider donating money to the nixCraft via PayPal/Bitcoin, or become a supporter using Patreon.
  11. How to view contents of tar file without extracting it
  12. To view a detailed table of contents for archive called my-data.tar.gz, use the following syntax:
  13. tar -ztvf my-data.tar.gz
  14. tar -tvf my-data.tar.gz
  15. tar -tvf my-data.tar.gz 'search-patter'
  16.  
  17. Examples: List the contents of a tar or tar.gz file
  18. Let us see some examples:
  19.  
  20. Task: List the contents of a tar file
  21. Use the following command:
  22. $ tar -tvf file.tar
  23.  
  24. Sample outputs:
  25.  
  26. Fig.01: List archive contents to screen
  27. Fig.01: List archive contents to screen
  28. Task: List the contents of a tar.gz file
  29. Use the following command:
  30. $ tar -ztvf file.tar.gz
  31.  
  32. Task: List the contents of a tar.bz2 file
  33. Use the following command:
  34. $ tar -jtvf file.tar.bz2
  35.  
  36. Task: Search for specific files
  37. In this example, look for *.pl (all perl files) inside a detailed table of contents for archive called projects.tar.gz:
  38. $ tar -tvf projects.tar.bz2 '*.pl'
  39.  
  40. Where,
  41.  
  42. t: List the contents of an archive.
  43. v: Verbosely list files processed (display detailed information).
  44. z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file.
  45. j: Filter archive through bzip2, use to decompress .bz2 files.
  46. f filename: Use archive file called filename.
  47. SHARE ON Facebook Twitter
  48. Posted by: Vivek Gite
  49. The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.
  50.  
  51. Your support makes a big difference:
  52. I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft takes a lot of my time and hard work to produce. If everyone who reads nixCraft, who likes it, helps fund it, my future would be more secure. You can donate as little as $1 to support nixCraft:
  53.  
  54. Become a Supporter Make a contribution via Paypal/Bitcoin
  55.  
  56. Notable Replies
  57. nixcraft says:
  58. Assuming that file name is demo.tar.gz, run:
  59.  
  60. tar ztvf demo.tar
  61. Look for 4th column:
  62.  
  63. drwxr-xr-x vivek/vivek 0 2018-12-31 19:13 t/
  64. -rw-r--r-- vivek/vivek 73 2018-12-31 19:13 t/resolv.conf
  65. -rw-r--r-- vivek/vivek 1123 2018-12-31 19:13 t/hosts
  66. Continue the discussion www.nixcraft.com
  67. 1 more reply
  68.  
  69. Participants
  70.  
  71.  
  72. Historical Comment Archive
  73. Comments 25 comment
  74. Shashi says: September 2, 2008 at 6:19 am
  75. Thanks a lot Vivek…This article is very useful for me….
  76.  
  77. Bolser says: September 15, 2008 at 3:25 pm
  78. Perfect!
  79.  
  80. I don’t know why I always forget this!
  81.  
  82. Also the ‘j’ trick is killer! I always just try to use ‘z’, and then give up when bzip won’t play. Now I just need to remember … use j in stead of z when bzip.
  83.  
  84. jitedar says: December 24, 2008 at 10:37 pm
  85. great and thx..
  86.  
  87. asd says: January 25, 2009 at 4:28 am
  88. thanks!
  89.  
  90. Amit Verma says: June 3, 2009 at 10:41 am
  91. Rule of Thumb –
  92. {
  93. Use ‘z’ while compressing/decompressing/listing the file with GZIP.
  94. Use ‘j’ while compressing/decompressing/listing the file with BZIP2.
  95. }
  96. – with tar command.
  97.  
  98. Thanks
  99. Amit Verma
  100.  
  101. Jeremy says: July 16, 2009 at 11:16 pm
  102. The exact thing I was looking for, worked like a charm! :)
  103.  
  104. Ankur Sinha says: August 27, 2009 at 9:57 am
  105. Good Work!!!
  106. Thanks!!!
  107. keep it up!!!
  108. ;)
  109.  
  110. Nomaun Khan says: September 22, 2009 at 2:20 pm
  111. Thanks for the helpful contests
  112.  
  113. kiran says: October 23, 2009 at 1:59 pm
  114. Thanks a lot for this post guys …:)
  115.  
  116. Keep it up …
  117.  
  118. Chris Henley says: February 16, 2010 at 9:22 pm
  119. thanks. I’m too lazy to read the man page.
  120.  
  121. ode says: September 8, 2010 at 10:11 am
  122. $ tar -tvf file.tar works for all three file formats.
  123.  
  124. $ unzip -l works for zip files
  125.  
  126. Stefan says: July 17, 2011 at 3:54 pm
  127. Thanks it works fine however do you know if there is a faster way maybe? I have a 6GB gzip file and it takes ages to list the contents. For smaller files it is ok but for big files it is a pain.
  128.  
  129. Fixticks says: July 21, 2011 at 9:25 pm
  130. man pages are too long, thanks vivek.
  131. @Stefan, u cud try
  132.  
  133. tar -ztvf file.tar.gz > files.txt
  134.  
  135. now i assume u may be looking for a certain file in that big gzip, so
  136.  
  137. cat files.txt | grep certain_file_name_or_part_of_it
  138.  
  139. and u can now check for multiple names without the initial wait of listing the big gz’s files.
  140. I know this coz i have just done it thanks to reading this blog.thx again Vivek.
  141.  
  142. Liban says: November 25, 2011 at 12:16 am
  143. I’m trying to find and display, but this isn’t working for me..
  144.  
  145. find -name “.gz” | tar -tvf {};
  146.  
  147. brisohn says: May 1, 2012 at 8:09 am
  148. try this:
  149. find -name “*.gz” -exec tar -tvf {} \;
  150.  
  151. Moron says: March 12, 2012 at 9:31 pm
  152. I am getting following error while looking for content of the tar file
  153.  
  154. $ tar -ztvf
  155. tar: illegal option — z
  156.  
  157. Usage: tar -{c|r|t|u|x} [ -BdDEFhilmopRsUvw ] [ -Number ] [ -f TarFile ]
  158. [ -b Blocks ] [ -S [ Feet ] | [ Feet@Density ] | [ Blocksb ] ]
  159. [ -L InputList ] [-X ExcludeFile] [ -N Blocks ] [ -C Directory ] File …
  160. Usage: tar {c|r|t|u|x} [ bBdDEfFhilLXmNopRsSUvw[0-9] ]
  161. [ Blocks ] [ TarFile ] [ InputList ] [ ExcludeFile ]
  162. [ [ Feet ] | [ Feet@Density ] | [ Blocksb ] ] [-C Directory ] File …
  163.  
  164. Piyush says: January 16, 2013 at 1:40 pm
  165. -z option option is not working on AIX
  166.  
  167. Vivek Gite says: March 7, 2016 at 1:28 pm
  168. Try following on AIX unix:
  169. gzip -d < file.tar.gz | tar xvf -
  170.  
  171. OR use following two commands:
  172. gunzip file.tar.gz
  173. tar -xvf file.tar
  174.  
  175. Read tar and gunzip man pages for more info on your AIX system.
  176.  
  177. Suresh says: July 17, 2012 at 7:06 am
  178. Sequence is important ! tar -ztfv will fail with error ‘v’ not found where as tar -ztvf works – since you need to specify the filename after the f option. Cheers!
  179.  
  180. Sunny Arora says: September 11, 2014 at 7:03 am
  181. I want to list the files out of file.tar.bz2 and grep a pattern (say all .c files).
  182. But executing the command ” tar -tjvf fiel.tar.bz2 | grep .c ” doesn’t give the desired output.
  183. Please suggest
  184.  
  185. mateen says: March 7, 2016 at 11:09 am
  186. tar -tjvf fiel.tar.bz2 | grep *.c would do
  187.  
  188. Vivek Gite says: March 7, 2016 at 1:09 pm
  189. A better option:
  190. tar -tjvf fiel.tar.bz2 '*.c'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement