Skip to content

Instantly share code, notes, and snippets.

@ntrepid8
Last active July 4, 2024 09:26
Show Gist options
  • Save ntrepid8/d1db06d5b51abbc48af78c7afa7b06d5 to your computer and use it in GitHub Desktop.
Save ntrepid8/d1db06d5b51abbc48af78c7afa7b06d5 to your computer and use it in GitHub Desktop.
Create tar.xz file with threads and progress bar

tar xz tips

Compress a directory using multiple threads and show a progress bar with this script:

#!/usr/bin/env bash

# example: tar_cJf.sh ./directory > directory.tar.xz

SOURCE="$1"

# get source size
SOURCE_SIZE=$(du -sk "${SOURCE}" | cut -f1)

# archive and compress
tar -cf - "${SOURCE}" | pv -p -s "${SOURCE_SIZE}k" | xz -6 --threads=6 -c -
 

sources:

@av1m
Copy link

av1m commented Sep 14, 2021

Thanks for this tips !
For information, --threads=6 can be withdrawn for the moment because it has not been implemented

Actually, man xz on version 5.2.4 give :

Threaded decompression hasn't been implemented yet. It will only work on files that contain multiple blocks with size information in block headers. All files compressed in multi-threaded mode meet this condition, but files compressed in single-threaded mode don't even if --block-size=size is used.

A small tips : the option -v to xz show a progress indicator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment