Let's assume I have a several gigabyte tar file, but I also happen to know that the very last file written to the archive is something important that I need. Since tar files are appended sequentially, is there a way I can make tar read into the archive from the end to find this file, instead of starting from the beginning and reading over gigabytes of irrelevant data?
No, unfortunately there is not. From Wikipedia
Yes; if you know the size of the file you want, you can copy the end of the tar with dd skip. or if you want to read the whole file once for later quick random access you can make an index with:
An example script:
We can efficiently seek to last file on archive if tar is created on storage which is seekable, i.e. on hard disks and not on tape. use GNU tar's -n or --seek option. ( see this GNU tar options page ) say for instance, file which is stored last with name last_file.txt , you could use following command
Which would simply extract last_file.txt. because tar format contains size of a each file in a header, it is possible to skip entire file efficiently using seek system call, (see tar file format )
To only list all files efficintley in a big archive, use