PowerShell: unzip, untar, extract 7z etc
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
- by default,
Expand-Archive
will create a parent folder to contain the archive. - To not create a parent folder, use
-PassThru
- if
-DestinationPath
is not given, it expands to the current directory.
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