Categories
SysOps

How to access specific file occurrence in tar archive

Access specific file occurrence in tar archive.

Tar archive file can be updated multiple times, so it can contain multiple occurrences of the same files.

$ tar --list --file archive.tar.gz
project/readme.txt
project/readme.txt
project/readme.txt
project/readme.txt
project/src/
[...]

You can access each occurrence using occurrence parameter (1 is the first occurrence).

$ tar --extract --to-stdout --occurrence=1 --file etc.tar project/readme.txt
Version: 1.0
$ tar --extract --to-stdout --occurrence=2 --file etc.tar project/readme.txt
Version: 1.1
$ tar --extract --to-stdout --occurrence=3 --file etc.tar project/readme.txt
Version: 1.2

This parameter is supported by list, delete, extract, and diff operations.