No. of files in Tar

Hi Frields,
I would like to know the number of files present in a tar without using the command tar -tvf |wc -l

Is their any command for this?

There is no command other than the tar t.
tar is short for tape archive - it was developed for sequential access in a tape drive. So there is no metadata like you have for a direct access filesystem.

Hi,

Please can you explain why you do not want to use this command.

Cheers,
Shazin

Hi,

Please can you explain why you do not want to use this command.

Cheers,
Shazin

Hi ,

I am looking for an alternative because, their are some thousand files present in the tar and I feel the tar -tvf command is scanning file by file which takes more time.

I am looking for an option, which will give the output much faster.

If you are not in control of creating the "tar" files then the only option is the "t" (or "-t" on some versions) switch as advised by "jim mcnamara".

Have you considered a script to index the "tar" archives and store that index alongside each "tar" file such that you only need to produce the files list once per archive?

In a similar situation I used multiple concurrent jobs in a quiet slot each night to index archive "tar" files in preparation for selective re-archiving without duplicate identical files.

this probably isn't the answer you were looking for, but opening with WinZip or WinRar will give you the number of files present in the archive (but even those provide a table of contents so i'm not sure this would be quicker than 'tar t').

Leppie is hinting that there are more modern ways of creating an archive file which have a directory at the front of the archive.