PowerShell: unzip, untar, extract 7z etc

By Xah Lee. Date: . Last updated: .

Here's how to decompress, unarchive, extract, zip, tar, 7z etc files.

unzip

# unarchive to current dir
Expand-Archive xyz.zip
# specify a output dir
Expand-Archive -Path ~/xyz.zip -DestinationPath  c:/Users/xah/out/
# literal input path
Expand-Archive -LiteralPath c:/Users/xah/xyz.zip

example script:

# unzip all *nb.zip files to a dir named x
dir * -Recurse -Include "*nb.zip" | Expand-Archive -PassThru -DestinationPath x

untar, ungzip, gunzip

Windows 10 has BSD tar builtin, at C:/Windows/system32/tar.exe

# extract .tar file
tar xvf filename.tar
# extract .tar.gz (.tgz) file
tar xvfz filename.tar.gz
# extract .tar.bz2 file
tar xvfj filename.tar.bz2
# extract .tar.xz file
tar xvfJ filename.tar.xz

Extract 7z

You have to install 7z. ([ https://www.7-zip.org/ ])

# extract to full paths of items
7z x filename

Extract lzip (.lz)

You have to install lzip. At https://www.nongnu.org/lzip/lzip.html

# extract .lz file
lzip -d filename

PowerShell zip tar

PowerShell

Practical How-To

list files

list dirs

on dir

on file

Windows config

zip tar

misc


PowerShell in Depth

Programing PowerShell

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples