3

I need to list the folder/files inside a certs.tar.gz which is inside file.tar without extracting them.

[root@git test]# tar -tf file.tar
./
./product/
./product/.git/
./product/.git/refs/
./product/.git/refs/heads/
./Release/add_or_modify.sh
./certs.tar.gz
[root@git test]#
jww
  • 97,681
  • 90
  • 411
  • 885
jerry
  • 45
  • 1
  • 5
  • From where you need the list ? From a shell command ? An executable ? If you just need to have the list from a shell to see what's inside, give a try to some file manager (Midnight Commander or a gui based file manager) – Gianluca Apr 10 '18 at 07:15
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Apr 10 '18 at 09:22

1 Answers1

5

You may want to use and condition:

tar -xf abc.tar "abc.tar.gz" && tar -ztvf abc.tar.gz

Explanation:

For listing of files we use

If file is of type tar.gz:

tar -ztvf file.tar.gz

If file is of type tar:

tar -tvf file.tar

If file is of type tar.bz2:

tar -jtvf file.tar.bz2

You can also search for files in any of the above commands. e.g:

tar -tvf file.tar.bz2 '*.txt'

For extracting files we use

tar -xf file.tar

In these commands,

  • t: List the contents of an archive.
  • v: Verbosely list files processed (display detailed information).
  • z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file.
  • j: Filter archive through bzip2, use to decompress .bz2 files.
  • f filename: Use archive file called filename.
  • x: Extract all files from given tar, but when passed with a filename will extract only matching files
Abhishek Keshri
  • 3,074
  • 14
  • 31