Tar

From wikinotes

tar is a tool to create compressed file archives.

Compress

# uncompressed
tar -cvf file.tar directory/

tar -cvf /out/file.tar \
  -C /some/in/dir     `# change directory when compressing (strip leading dirs)` \
  dir-to-archive

# GZIP Compression
TODO

# LZ4 Compression
tar -cvf - folderABC | lz4 > folderABC.tar.lz4

Extract

tar -xvf file.tar          # extract in current dir
tar -xvf file.tar -C out/  # extract in out/

# extract single-file preserving hierarchy
tar -xvf file.tar \
  -C out \
  some/path/file.txt

# extract single-file, and strip the first 2x relpath dirs from it
# produces: out/path/file.txt (some/long have been removed)
tar -xvf file.tar \
  -C out \
  --strip-components 2 \
  some/long/path/file.txt

Extracting compressed files

# LZ4
lz4 -dc --no-sparse file.tar.lz4 | tar -x