Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

3 Answers

up vote 5 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
add comment

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
add comment

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/
share|improve this answer
add comment

Your Answer

 
discard

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.