Search notes:

tar.exe

tar.exe is the bsdtar archive tool. With Windows 10 (build 17063), it comes preinstalled under C:\Windows\System32.

Commands

When tar.exe is invoked, one of five commands (aka mode specifiers) must be specified with:

The -f flag

By default, without specifying a file with -f, tar.exe tries to operate on a file (device?) named \\.\tape0. Of course, on most (if not virtually all) Windows systems, such a file does not exist and tar.exe errors out with tar.exe: Error opening archive: Failed to open '\\.\tape0'.
Therefore, it is necessary to specify the archive file with the -f option.
The -f can be appended to the mode specifier. The following two commands are equivalent:
C:\path\to\directory> tar -t -f some.zip
C:\path\to\directory> tar -tf   some.zip

Creating an archive

A simple tar archive is produced with the -c and -f flags.
C:\path\to\directory> tar -c -f someArchive.tar src
For convenience, the -c and -f can used without hyphen in one word like so:
C:\path\to\directory> tar cf someArchive.tar src
It's possible to create a gzip archive by also specifying the z flag:
C:\path\to\directory> tar czf someArchive.gzip src
A zip file can be created with the undocumented(?) option a (Thanks to Andre Giese for the helpful tip!)
C:\path\to\directory> tar caf someArchive.zip file-one.txt file-two.txt
It should be noted that files listed for archival must not have a dot slash (both forward and backslash). Such files will be silently ignored when creating the archive.
In the following example, only file-one.txt is added to the zip file:
C:\path\to\directory> tar caf someArchive.zip file-one.txt ./file-two.txt .\file-three.txt

Listing the contents of an archive file

The contents of an archive file can be displayed with the -t command:
C:\path\to\directory> tar -tf some.zip

Extracting (untarring) a file

In order to extract the contents of a file, the options -x and -f need to be given. -f specifies the filename of the tar file. -x tells tar.exe to extract all files.
C:\path\to\directory> tar -xf someFile.tgz

Keep existing files

In order to make sure that existing files are not overwritten when files are extracted from an archive, the -k flag does that.

Only extracting patterns

In the extract command, the patterns of the files to be extracted can be specified:
C:\path\to\directory> tar -xf someFile.tgz foo*.exe bar*.dll

Specify the extract-destination directory

By default, tar.exe extracts the directory tree structure of an archive relative to the current directory. The -C option allows to specify an alternative destination:
C:\path\to\directory> tar -xf someFile.tgz -C %TEMP%
If the -C option is combined with file names to be extracted, the file names need to be placed after the -C option:
C:\path\to\directory> tar -xf someFile.tgz -C %TEMP% readme.txt source. …

See also

Linux shell: tar
archiveint.dll
Tar and Curl Come to Windows!

Index