Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
up vote 7 down vote accepted

How about something like:

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

share|improve this answer
Wow! That's great. Thanks – santiago.basulto Nov 24 '10 at 21:49
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.)

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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