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!!



How about something like:

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

  • 3
    Slow for large tarballs, but workable – Nicu Stiurca Aug 20 '14 at 21:27

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.)

  • Easier to understand and remember and plenty fast. – Walf Mar 1 '17 at 2:56
  • 2
    This is great, but I'll never remember that -t means list. So -tf can be converted to --list -f. – spinup Oct 18 '17 at 16:24
  • This option is much faster than the accepted answer, thank you! – Dr_Zaszuś Jan 17 '18 at 8:15
  • To see the first level of hierarchy I used tar --exclude='*/*/*' -tf yourarchive.tar – user3804598 Jul 25 '19 at 14:33

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+)*/?$'


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.