跳到主要内容

Compress

curl -O https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz
tar zxvf rarlinux-x64-612.tar.gz
./rar/unrar
提示
  • 文件归档 区别于 压缩算法 - 归档 -> 容器
  • gzip 头包含 mtime,因此压缩结果是不一致的

cd staged && mytar cf - . | ssh root@localhost "cd / && tar xvf -"

# 7z
# https://github.com/p7zip-project/p7zip
apk add p7zip
7z a dir.7z -m0=zstd -mx7 dir

# bz2
# ==========
# 解压
bzip2 -d filename.bz2
# 解压并保留原始压缩包
bzip2 -dk filename.bz2

# 并行 Gzip
# http://zlib.net/pigz/
# 提亚提升不大, 因为解压的结构不适用于并发
# 支持 -11 zopfli
# 利用 pv 可以查看压缩进度
pv dict.db | pigz -vfk9 > dict.db.gz

# 可以直接替换
ln -s /usr/bin/pigz /usr/local/bin/gzip
ln -s /usr/bin/unpigz /usr/local/bin/gunzip

# 强制覆写, 暴露原始文件, 9 级压缩
gzip -vfk9 data.db > data.db.gz

# -w 0 自动选择优化的窗口大小
# -9 压缩率, 如果不指定, 默认为 -Z 即 11, 会非常慢
pv dict.db | brotli -9 -w 0 > dict.db.br

# 编码
# ====
# https://www.iana.org/assignments/character-sets/character-sets.xhtml
unzip -O cp936 -l my.zip # 使用指定的编码, 有些 unzip 不一定有该选项 - unzip-iconv
# 也可以先解压, 然后再转换
LANG=C 7za x your-zip-file.zip
convmv -f GBK -t utf8 --notest -r .
# brew install unar
unar -e gb18030 gb18030.zip

# 批量
# ====
unzip \*.zip
gzipdeflate/zlib
Header size10 bytes2 bytes
Footer size4 bytes0
ChecksumCRC32Adler-32
Compression algorithmDEFLATEDEFLATE
SpecificationRFC1952RFC1950

zlib

  • CMF
    • 0-3 CM Compression method
      • 8 -> deflate
    • 4-7 CINFO Compression info
      • CM=8 LZ77 window size, CINFO=7 -> 32K window size
  • FLG
    • 0-4 - FCHECK (check bits for CMF and FLG)
    • 5 - FDICT (preset dictionary)
    • 6-7 - FLEVEL (compression level)
      • 0 - fastest
      • 1 - fast
      • 2 - default
      • 3 - maximum compression, slowest algorithm

gzip

flg-
0store - 不压缩
1compress
2pack - 打包
3lzh 使用 lzh 算法压缩
4-7保留
8deflate - 常用
hdr-
0b00000001可能为文本格式
0b00000010多压缩文件 - 存在序列
0b00000100包含附加字段
0b00001000包含文件名
0b00010000包含文件注释
0b00100000加密
0b11000000保留

| os | | ---- | -------------------------- | | 0x00 | Windows | | 0x01 | Amiga | | 0x02 | VMS/OpenVMS | | 0x03 | Unix/Linux/macOS | | 0x04 | VM/CMS | | 0x05 | Atari TOS | | 0x06 | HPFS filesystem (OS/2, NT) | | 0x07 | Macintosh | | 0x08 | Z-System | | 0x09 | CP/M | | 0x0a | TOPS-20 | | 0x0b | NTFS filesystem (NT) | | 0x0c | QDOS | | 0x0d | Acorn RISCOS | | 0xff | unknown |


  • rfc1952 GZIP file format specification version 4.3

FAQ

解压 7z exe

ls *.exe | xargs -n 1 -d "\n" 7z x

Multi part

# 1. merge
cat in.zip* > ~/in.zip
unzip in.zip

# 2. 7z
7z x in.zip.001

Password

7z -mhc=on -mhe=on -pPASSWORD a out.7z in.txt

zip -P password -r encrypted.zip folderIWantToZip
unzip -P password encrypted.zip

zstd level