163

Suppose I have two files:

  • file1.zst
  • file2.tar.zst

How can I decompress these files in terminal?

Quarkonia
  • 1,811
  • 2
  • 11
  • 11

6 Answers6

212

The extention .zst means that the archive is compressed by zstd.

The tar command has an option -I (--use-compress-program) to specify a command for compression/decompression.

You can use it as follows.

$ tar --use-compress-program=unzstd -xvf archive.tar.zst
ericbn
  • 10,163
  • 3
  • 47
  • 55
s-yata
  • 2,152
  • 1
  • 9
  • 2
  • 8
    tar (child): zstd: Cannot exec: No such file or directory – Nike Oct 26 '17 at 19:39
  • 20
    @user1271772 Might not be installed. For Debian, `sudo apt-get install zstd`. `yum` or whatever for other distros. – hBy2Py Mar 14 '18 at 17:49
  • 4
    Is there a way without installing anything extra? I don't have sudo permission on the server. I would rather not have to scp the file to a different machine, uncompress, then transfer back. – Nike Mar 19 '18 at 02:33
  • 1
    @user1271772 you could build it from source – Suici Doga May 07 '18 at 09:57
  • @SuiciDoga: Good idea. Though it's unfortunate we can't decompress these files more "natively". – Nike May 07 '18 at 16:55
  • @user1271772 if you want to uncompress natively you could install the package – Suici Doga May 08 '18 at 02:09
  • @SuiciDoga: I just explained that I don't have sudo permission. So as you say, the only way is to install from source, but that is not "native". It would be nice if the Linux distribution had this program just like it comes with the programs "grep" and "vi" – Nike May 08 '18 at 02:45
  • @user1271772 ubuntu is going to use zstd by default in the future – Suici Doga May 09 '18 at 05:48
  • 8
    The `-I` or `--use-compress-program` argument only works if I use the equal sign format on the Mac. So, `tar -I=/usr/local/sbin/zstd -xvf archive.tar.zst` works but the one given above doesn't. see detail on https://www.gnu.org/software/tar/manual/html_node/gzip.html – Devy May 09 '19 at 18:35
  • This tar command also works fine in `Git-Bash`, if you are on Windows. – Amit Naidu Apr 15 '20 at 21:45
  • 3
    If you want to extract you have to select `unzstd`. The following worked for me: `tar --use-compress-program=unzstd -xvf archive.tar.zst` – Ger May 04 '20 at 12:47
  • 1
    If you're `tar` has builtin zstd support you can just use `tar axvf archive.tar.zst` which will autodetect the compression format. – Jeff Muizelaar Nov 19 '21 at 19:09
  • How do I decompress this file type on Windows? – Aaron Franke Nov 28 '21 at 03:58
  • @user1271772 If by natively you mean without explicitly running a compiler or `make` you can create a local python environment e.g with `virtualenv`, `pip install zstandard` and write your own `unzstd` as `import zstandard; import sys; zstandard.ZstdDecompressor().copy_stream(sys.stdin.buffer, sys.stdout.buffer)` (not tested, following Jonathan's answer below). – Joachim Wagner Sep 13 '22 at 11:45
  • My GNU `tar` (version 1.30, supplied by Ubuntu 20.04) supports the `--zstd` flag to support archives in zstd format. It requires the `zstd` executable. – reinierpost Oct 26 '22 at 12:21
  • slight modification. I did'nt have `unzstd` but have `zstd`. So did this in two steps: zstd -d openssl-1.1-1.1.1.s-2-x86_64.pkg.tar.zst` then `tar xvf openssl-1.1-1.1.1.s-2-x86_64.pkg.tar` then copied libssl.o and libcrypto.o in /usr/lib64 appened with .1.1 in the end, then created symlinks to the original name. – FractalSpace Nov 30 '22 at 23:44
131

Decompress it in Terminal.

unzstd yourfilename.zst

I know there aren't many resources available but I found this here: http://manpages.org/zstd

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Kaleba KB Keitshokile
  • 1,656
  • 1
  • 6
  • 12
  • 2
    you have to install the package `zstd` for the unzstd command. note, that it has problems with a colon in the package name, so rename those packages beforehand – rubo77 Jun 20 '20 at 04:35
  • @rubo77 For me, it works with a colon, must be updated or something. But what I am guessing is that your shell is not working and maybe quote it with `''` or `""`, or you can just escape it with \. –  Apr 17 '21 at 06:10
23

If you have a standard cmake + gcc build stack:

git clone https://github.com/facebook/zstd.git
cd zstd/build/cmake
cmake .
make
./programs/zstd -d /path/to/file.zst
schuess
  • 1,009
  • 1
  • 10
  • 21
  • 3
    as someone without root permissions, this answer was amazingly helpful and complete. Cannot thank you enough – Max F Apr 24 '20 at 21:55
13

On macOS Mojave 10.14.3, I was unable to specify the compression algorithm using the -I flag. Doing it this way worked for me;

Install zstd using brew if you don't already have it installed.

  1. Decompress from .zst: unzstd filename.tar.zst or zstd -d filename.tar.zst. filename.tar will be created.
  2. List compressed archive: tar tf filename.tar.
  3. Extract the compressed archive: tar xf filename.tar.

Hope this helps.

DKMDebugin
  • 551
  • 7
  • 16
4

Download the Python library and then you can use Python like following:

import zstandard as zstd
dctx = zstd.ZstdDecompressor()
with open(submission_path_read, 'rb') as ifh, open(submission_path_save, 'wb') as ofh:
    dctx.copy_stream(ifh, ofh, write_size=65536)
Jaroslav Bezděk
  • 6,967
  • 6
  • 29
  • 46
Jonathan Lam
  • 1,237
  • 3
  • 20
  • 49
  • no need to use the python wrapper for zstandard here, and this python script starts with an `elif` so will not even run... – Peter M Jun 17 '19 at 20:42
  • How will you decompress on windows? – Jonathan Lam Jun 17 '19 at 21:20
  • Fair enough. Still, this is not a functioning python script (starts with `elif` poorly described variables, leaves out some sort of file-path selection mechansim?, …). On top of that, from what I can tell, this would just decompress to a `.tar` archive which is a solution to only half of the poster's problem. – Peter M Jun 19 '19 at 15:35
  • 2
    That's why there is ... The code is not complete. OP question's title was How to decompress. I answered that. – Jonathan Lam Jun 24 '19 at 16:57
  • 2
    This is useful, saved me further trouble adding a package to git-for-windows (MSYS2) avoiding all manner of hoops. And it works on Windows. Used `python -m pip install zstandard` to install the module. – Ed Randall Dec 11 '20 at 15:53
  • 1
    Thanks @EdRandall. I don't know why people would downvote it tho :) – Jonathan Lam Dec 12 '20 at 19:19
  • 3
    It will decompress it to tar. Then I used 7zip to decompress it to normal folder. – OhhhThatVarun Jan 09 '21 at 19:44
  • 2
    this was useful to me. especially the streaming part – user1043144 Dec 18 '21 at 21:20
  • 1
    Worked for me on windows 10. – Saurabh Jain Dec 14 '22 at 11:48
3

I found some of these files in the Anaconda downloads. After I installed Anaconda, I was downloading additional packages. The downloaded packages in my Anaconda download directory were zip files (without the .zip extension), but they had these .tar.zst files inside them. That led me to stackoverflow to figure out what they were, which led me to this question. If you're in the same boat, then Anaconda also supplies the answer.

It turns out that the zstd and unzstd executables are also installed by the Anaconda installer, so they should be available at the command line if you're in your Anaconda environment.

phrodod
  • 156
  • 1
  • 8