17

I've a tar (gz, bzip) file and want to see its content, but not recursively.

This is: The "first level" in the file.

I already know how to see content:

tar -ztf file.tar.gz

But it's recursive!!

Thanks!

santiago.basulto
  • 598
  • 2
  • 8
  • 16

3 Answers3

20

tar --exclude='*/*' -tf yourarchive.tar should do it.

That's almost certainly a GNU tar-ism. But who doesn't use GNU tar, right? (Another fun fact: in recent versions of GNU tar, you don't need the 'z' or 'j' to list or uncompress .gz or .bz files -- it autodetects those and it just works.)

mattdm
  • 6,550
  • 1
  • 25
  • 48
11

How about something like:

tar -ztf file.tar.gz | egrep '^[^/]+/?$'

dmah
  • 516
  • 3
  • 5
1

This should show top-level directories as well as just files that include the dot character:

$ tar -tf app.tar.gz | grep -E '^\w+(\.\w+)*/*\w+(\.\w+)*/?$'

django/
django/django.wsgi
django/search_indexes/
django/templates/
django/app/
django/other-app/
Sam Halicke
  • 6,122
  • 1
  • 24
  • 35