How to use tar with lz4?

2020-05-27 18:05发布

问题:

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

回答1:

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.



回答2:

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