Linux command line – search a file inside a tar archive

linuxtar

I would like to check whether a file is in a gzip'ed tar archive.
For example I want to check whether the /etc/passwd is present in the archive backup_2010-09-27.tar.gz

A dumb solution can be:

tar -tzf backup_2010-09-27.tar.gz | grep '/etc/passwd'

But that takes time. Is there a better solution?

Best Answer

Try this (omit the initial slash):

tar -tzf backup_2010-09-27.tar.gz etc/passwd