19

How to use tar and filter the archive through LZ4? Or any available tools? It looks cumbersome to use tar cvf folderABC.tar folderABC && lz4c -c0 folderABC.tar.

PS: *nix environment

Adam Katz
  • 14,455
  • 5
  • 68
  • 83
Daniel
  • 2,576
  • 7
  • 37
  • 51

4 Answers4

34

lz4 has a command line structure similar to gzip. Therefore, something like this will work :

tar cvf - folderABC | lz4 > folderABC.tar.lz4

or

tar cvf - folderABC | lz4 - folderABC.tar.lz4

First one compresses silently, like gzip. Second one is a bit more lz4-specific, and will also display summarized compression stats.

Decompression would go like this :

lz4 -d folderABC.tar.lz4 -c | tar xvf -
Cyan
  • 13,248
  • 8
  • 43
  • 78
26

On GNU tar, you can use -I lz4

Both FreeBSD and GNU tar seems to support --use-compress-program=lz4 as well.

tar -I lz4 -cf archive.tar.lz4 stuff to add to archive
tar -I lz4 -xf archive.tar.lz4

or

tar --use-compress-program=lz4 -cf archive.tar.lz4 stuff to add to archive
tar --use-compress-program=lz4 -xf archive.tar.lz4
Gert van den Berg
  • 2,448
  • 31
  • 41
  • `You must specify one of the '-Acdtrux', '--delete' or '--test-label' options` – Gaia Dec 05 '19 at 03:41
  • @Gaia I would normally use `-cf` and `-xf`. Not sure if it is portable to non GNU tar versions, so I kept the style of the question. (edited answer) – Gert van den Berg Dec 06 '19 at 08:54
2

To use -I in GNU tar, you must specify it AFTER destination file as this:

tar cvf /path/to/destinationfile.tar.lz4 -I lz4 /path/to/archive
JTerry
  • 29
  • 2
2

Install lz4

sudo apt install lz4

Compress

tar --use-compress-program=lz4 -cvf target.lz4 /source/files

Decompress

tar --use-compress-program=lz4 -xvf target.lz4 -C /destination
skyehash
  • 31
  • 1