PowerShell: unzip, untar
unzip
# unarchive to current dir Expand-Archive xyz.zip # specify a target dir Expand-Archive -Path c:/Users/xah/xyz.zip -DestinationPath c:/Users/xah/out/ # using literal path, no expansion Expand-Archive -LiteralPath c:/Users/xah/xyz.zip -DestinationPath c:/Users/xah/out/
- 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 some.tar # extract .tar.gz (.tgz) file tar xvfz some.tar.gz # extract .tar.bz2 file tar xvfj some.tar.bz2 # extract .tar.xz file tar xvfJ some.tar.xz
Decompress using 7z
You have to install 7z. ([ https://www.7-zip.org/ ])
# extract to full paths of items 7z x archiveName
Compress by zip
Compress-Archive c:/Users/xah/Pictures/ c:/Users/xah/pic.zip
Note: the max zip file Compress-Archive
can create is 2 GB.
As of 2021-11-07.
See help Compress-Archive
Use 7z instead.
Create Tar Archive
Windows 10 has BSD tar builtin, at
C:\Windows\system32\tar.exe
# create tar file tar cvf dirname.tar dirname
tar -h
for help.
For more detail see
Linux: Compression How-to: tar gzip bzip2 xz 7zip rar zip
Compress using 7z
7z a c:/Users/xah/Pictures.7z c:/Users/xah/Pictures/
7z a c:/Users/xah/Pictures.zip c:/Users/xah/Pictures/