Questions & Answers

Use tar to extract files from an archive with an unknown name

I would like to use tar (on Windows) in a command line to extract files from an archive, that has a variable name, like *, that I don't know beforehand. I haven't found a way to use a wildcard for the targeted archive name, is there an option to do that ?

I have tried things like tar -xf "*", but it searches for a file with the same exact name, not the pattern.


2023-01-19 00:00:08
A simple search with tar manual in any www search engine should lead you to the GNU tar manual which contains the necessary information on how to use wildcard patterns by tar itself and not by the shell interpreter. The Linux/Mac shell interpreters replace "*" by a list of argument strings passed to tar matching this wildcard pattern. The Windows Command Processor cmd.exe does not do that. But tar.exe can be instructed to search itself for ZIP files matching this wildcard pattern.
Answers(1) :

Use 'tar --wildcards ...' (works at least with tar 1.33). Example:

╰─➤ $ tar --wildcards -tvf /home/johndoe/.cpan/sources/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz '*enc'
-rw-r--r-- todd/staff    40706 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/big5.enc
-rw-r--r-- todd/staff    45802 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/euc-kr.enc
-rw-r--r-- todd/staff     1072 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/ibm866.enc
2023-01-19 00:00:08
Could you please submit an answer which suits the tags [windows] and [cmd], not just something which matches the tag [tar].