2

I have a tar file which gets updated many times, and there are multiple copies of the same file. I've found the latest version of the file gets extracted using -x.

For example: I have a save.tar file that contains 3 versions of a.txt: a.txt version1 "this is not done" a.txt version2 "this is correct." a.txt version3 "this is broke."

How do I extract a.txt (the version2)

2 Answers 2

3

Approx. 40 years ago, there was a discussion whether tar could get an option to specify the n-th occurence that should be extracted but I am not sure whether this is a good idea.

With a standard tar implementation, you could call:

tar xvwf archive.tar

and then interactively confirm the extraction for the "right" version.

With star, there is an additional method:

star -xv < archive.tar -find -mtime +some-time-spec -mtime -other-time-spec

and use two useful time specifiers to select the "right" version.

See: http://schilytools.sourceforge.net/man/man1/star.1.html

You of course need to use an additional path name selector in case that the archive file contains more differen filenames. So with a standard tar, this becomes:

tar xvwf archive.tar a.txt

and with star it becomes:

star -xv < archive.tar a.txt -find -mtime +some-time-spec -mtime -other-time-spec

or:

star -xv < archive.tar -find -path a.txt -mtime +some-time-spec -mtime -other-time-spec
1

From this page:

--occurrence=n

The default for n is 1, or the first occurance of the member.

1
  • @Freddy: Thanks. Commented Jan 30, 2023 at 0:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.