.tar
Archive
TAR(磁带归档)
TAR 是一种 Unix 归档格式,将多个文件和目录捆绑到单个未压缩文件中,同时保留权限、所有权和时间戳。TAR 几乎总是与压缩工具(gzip、bzip2、xz)配对使用,创建 .tar.gz、.tar.bz2 或 .tar.xz 归档。
MIME 类型
application/x-tar
类型
二进制
压缩
无损
优点
- + Preserves Unix permissions, ownership, symbolic links, and timestamps
- + Streaming-friendly — can be created and extracted via pipes
- + Standard on all Unix/Linux systems with no additional software
缺点
- − No built-in compression — must be combined with gzip, bzip2, or xz
- − No random access — extracting one file requires reading sequentially
- − Less intuitive for Windows users than ZIP
何时使用 .TAR
在 Unix/Linux 备份、源代码分发和 Docker 镜像层中使用 TAR(配合压缩)。
技术细节
TAR 文件是一系列 512 字节块。每个文件条目有一个包含元数据的头部块,后跟数据块。TAR 本身不执行压缩 — 它严格来说是一种归档(拼接)格式。
历史
TAR 于 1979 年为 Unix Version 7 创建,用于将文件归档写入磁带。POSIX.1-2001 标准(pax 格式)通过扩展头部对 TAR 进行了现代化,支持长文件名和大文件。