Home / Alt manpages / pzstd(1)

  • pzstd(1)
  • User command
  • linux

Compress and Verify Files in Parallel with pzstd

You will turn ordinary files into Zstandard .zst files, check their integrity, and restore them without losing the originals. Allow about ten minutes for a first run. The examples use only a temporary working directory; no elevated privileges are needed.

1. Check which pzstd you are running

There are two useful version checks here. The installed zstd Debian package is reported as 1.5.5, while this host's PATH selects a Homebrew pzstd binary reporting 1.5.7. That distinction matters when behaviour or diagnostics differ between machines. The local manual page describes PZSTD version 1.5.5 and is the reference for the options in this guide.

$ command -v pzstd
/home/linuxbrew/.linuxbrew/bin/pzstd
$ pzstd --version
PZSTD version: 1.5.7.
$ dpkg-query -W -f='${Package} ${Version}\n' zstd
zstd 1.5.5+dfsg2-2build1.1

Use the version printed by the command when recording a reproducible procedure. If command -v prints nothing, install the package through your normal system-management process. Do not use sudo merely to compress files you can already read.

2. Compress one file and keep the source

Create a small test file or replace the path below with an existing file you own:

$ work=$(mktemp -d /tmp/pzstd-work.XXXXXX)
$ printf 'backup candidate\n' > "$work/notes.txt"
$ pzstd -p 2 "$work/notes.txt"
$ ls -l "$work"
notes.txt
notes.txt.zst

With one input file, pzstd writes a compressed file beside it and normally leaves the input in place. The -p 2 option limits compression and decompression to two threads. If you omit it, the programme chooses its default thread count. The short compression-level options are -1 through -19; this guide leaves the level at its normal default because a higher number trades time and memory for a smaller result.

Checkpoint: confirm both files exist before doing anything that removes a source:

$ test -r "$work/notes.txt" && test -s "$work/notes.txt.zst" && echo 'source and archive are present'
source and archive are present

3. Test the compressed file before relying on it

Use -t to check the integrity of a compressed file without extracting it:

$ pzstd -t "$work/notes.txt.zst"
/tmp/pzstd-work.XXXXXX/notes.txt.zst: 16 bytes

The temporary directory name and byte count will differ. The important result is a successful exit status and no corruption error. If the test fails, keep the original source, copy the damaged archive aside for investigation, and create a fresh archive. Do not delete the only copy to make the error disappear.

4. Decompress to a deliberate destination

For a single compressed input, decompression normally derives the output name by removing .zst. Use -c when you want the restored bytes on standard output, which makes the destination explicit:

$ pzstd -d -c "$work/notes.txt.zst" > "$work/restored.txt"
$ cmp "$work/notes.txt" "$work/restored.txt" && echo 'restored data matches'
restored data matches

Shell redirection can truncate an existing destination before pzstd starts. Choose a new name such as restored.txt, or make a backup first. If you need a named output and have exactly one input, the manual also provides -o FILE:

$ pzstd -d -o "$work/restored-again.txt" "$work/notes.txt.zst"
$ cmp "$work/notes.txt" "$work/restored-again.txt" && echo 'explicit output matches'
explicit output matches

5. Process several files without accidental deletion

Pass multiple paths when you want each file handled independently. Keep the default source-preserving behaviour while you inspect the results:

$ printf 'second file\n' > "$work/another.txt"
$ printf 'third file\n' > "$work/third.txt"
$ pzstd -p 4 "$work/another.txt" "$work/third.txt"
$ find "$work" -maxdepth 1 -type f -name '*.zst' -print
/tmp/pzstd-work.XXXXXX/another.txt.zst
/tmp/pzstd-work.XXXXXX/third.txt.zst

The -r option makes directory processing recursive. Treat it as a scope decision: check the directory contents first, and do not point it at a mount containing unrelated data. For a large tree, start with a representative subdirectory and check the resulting names before expanding the command.

6. Remove sources only after verification

Warning

--rm deletes source files after successful compression or decompression. That is a destructive change. It does not replace an independent backup, and a command aimed at the wrong directory can remove more than intended.

After testing an archive and checking your backup policy, use an explicit file list first:

$ pzstd -t "$work/notes.txt.zst" && pzstd --rm -f "$work/notes.txt"
$ test ! -e "$work/notes.txt" && test -s "$work/notes.txt.zst" && echo 'source removed after compression'
source removed after compression

There is no undo command for --rm. Recovery requires another copy, such as a verified archive or backup. The -f above is needed because the destination already exists from step 2: it overwrites that destination without prompting. Use it only after inspecting the paths. If you only wanted to prevent overwriting an existing result, leave out -f and review the prompt.

7. Use standard output for a pipeline

-c writes compressed or decompressed data to standard output. This is useful when another command owns the destination, but keep diagnostics separate from data and avoid sending binary output directly to a terminal:

$ pzstd -c "$work/notes.txt" > "$work/notes-from-stdout.zst"
$ pzstd -t "$work/notes-from-stdout.zst" && echo 'standard-output archive is valid'
standard-output archive is valid

For shell scripts, check the exit status after every compression or decompression operation. A file existing is not enough: a failed pipeline can leave a truncated destination.

Done means

  • You recorded the actual pzstd --version selected by PATH.
  • Your compressed file passed pzstd -t.
  • You compared restored data with cmp before treating it as recovered.
  • You used -p when the thread limit mattered.
  • You kept sources until verification and understood that --rm has no built-in undo.