LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar -tf going slow (https://www.linuxquestions.org/questions/linux-newbie-8/tar-tf-going-slow-741114/)

plebetan 07-18-2009 11:08 PM

tar -tf going slow
 
I recently created a tar file containing several large files(like 50-200 MB each). I understand that it could take a while to add or extract large files, but I am just trying to list the files in the archive.

I do a "tar -tf file.tar", and it takes like 3 minutes to list the 15 files in the archive. Don't tar files keep an index of the files added to them?

So, is this normal behavior? why would filesize affect the time it takes to list files?

anomie 07-19-2009 12:13 AM

Yes, it seems to be normal behavior. No, there is almost certainly no index created by tar for its archives. (Where would it live?)

I did a little experiment to confirm what you're describing:
Code:

$ du -h foo bar baz boo
4.0K    foo
4.0K    bar
338M    baz
331M    boo

$ tar cf one.tar foo bar

$ tar cf two.tar baz boo

$ time tar tf one.tar
foo
bar

real    0m0.171s
user    0m0.000s
sys    0m0.001s

$ time tar tf two.tar
baz
boo

real    0m14.560s
user    0m0.027s
sys    0m1.266s

It took the one.tar archive (which contains tiny files) a fraction of a second to be listed. It took the two.tar archive (which contains 300MB+ files) over 14 seconds to be listed.

My WAG is he is actually extracting files to a temporary area - or /dev/null - just to do the listing. I didn't measure disk I/O, but I suspect you'd find lots of activity while listing a large archive.

plebetan 07-19-2009 05:49 PM

I would have expected that there was some kind of table of contents or index at the beginning of a tar file. kind of like with filesystems. I mean, an empty tar archive takes up 10K. It seems so inefficient to extract every file in a tar when you only need to list filenames. especially with large files.


All times are GMT -5. The time now is 10:05 PM.