坑人的macos tar 命令 (实际上是bsdtar)换用 gnu tar

周末 看着笔记本上好用的朗文当代高级词典(mac版)和其它两部词典,准备复制到黑苹果台式机上去。考虑到词典内容有太多小文件,普通复制传输太慢,毫无疑问用 tar 打包肯定快而且能保留原始文件的各种信息。命令如下:

bash 复制代码
time tar czf ~/tmp/Diction.tgz ./LDOCE5.dictionary ./ccald.dictionary 

大约3分钟左右结束,sftp 上传台式机。运行 解压命令:

bash 复制代码
$ tar xf ~/Diction.tgz 
tar: Special header too large
tar: Error exit delayed from previous errors.

这什么意思?赶快在笔记本上测试一遍,结果一样。用了这么多年Linux和macos 这是第一次碰到tar命令创建成功 但解压却失败,如果这是备份关键文件,后果无法想象。网上搜索了一下,看到下面的内容:

https://forums.freebsd.org/threads/tar-special-header-too-large-error.73612/

bash 复制代码
tar: Special header too large error | The FreeBSD Forums
Jan 8, 2020 · I'm piping a bzip2 compressed tar file into tar on FreeBSD 11.2-RELEASE and seeing this error. Anyone any idea what this may indicated? I suspect that after this 

嗯 对解决问题毫无用途,不过发现一点,这个应该是 bsdtar出现的问题。

bash 复制代码
$ ls -l `which tar`
lrwxr-xr-x  1 root  wheel  6 Feb 26 13:47 /usr/bin/tar -> bsdtar

去GNU官网 ​​​​​​https://ftp.gnu.org/gnu/tar/ 下载最新版 tar ,命令行编译:

bash 复制代码
$ tar xf ~/Downloads/tar-1.35.tar.xz
$ cd tar-1.35
$ ./configure
$ make

.......
  CC       xattrs.o
  CCLD     tar
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _utf8_convert in utf8.o
  "_iconv_open", referenced from:
      _utf8_convert in utf8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tar] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
make  35.08s user 11.97s system 90% cpu 52.118 total

本以为是个简单的库文件问题,结果搜索半天毫无进展,花的时间可以直接传输几遍了,不过这么简单的问题都解决不了,还怎么开发程序?终于下定决心,直接改Makefile,为保险起见,先添加 -v 参数到Link命令参数中:

bash 复制代码
$ mvim src/Makefile
  LDFLAGS = -v
$ make
  CCLD     tar
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 12.0.0 13.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o tar -L/usr/local/lib buffer.o checkpoint.o compare.o create.o delete.o exit.o exclist.o extract.o xheader.o incremen.o list.o map.o misc.o names.o sparse.o suffix.o system.o tar.o transform.o unlink.o update.o utf8.o warning.o xattrs.o ../lib/libtar.a ../gnu/libgnu.a -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/lib/darwin/libclang_rt.osx.a

仔细看 没有 iconv库,虽然 Makefile 中有 LIBICONV = -liconv

但链接时却没有库,原因未知,哎 算了,简单点直接在 src/Makefile 中修改LDFLAGS 如下:

bash 复制代码
LDFLAGS = -liconv -v

再次 make 成功!用 gnu tar 打包 ,没有任何问题。那么,用 bsdtar 就没有办法了?还是有的,用man 查看了 bsdtar的用法 可用下述命令解决:

bash 复制代码
time bsdtar -c --no-mac-metadata -z -f ~/tmp/Diction4.tgz ./LDOCE5.dictionary ./ccald.dictionary

没错,加个 --no-mac-metadata 参数即可,当然这会损失部分mac特有的元数据信息。

网上有很多对比 bsdtar 和 gnu tar 的,都认为 bsdtar 在 稀疏文件有优势,不过经历这个创建文件不报错,解压却会报错的特例,还是小心为上,最好备份后验证一下;或者选用 gnu tar 吧好像还没听说过有类似问题。

一个小小的问题,浪费大半天时间,还是写下来 以备参考。

相关推荐
aosky20 小时前
手机远程畅玩OpenAI Codex
macos·智能手机·cocoa
A懿轩A1 天前
【2026 最新】Python 下载与安装:在 macOS 下使用 Homebrew 和 pyenv 完美管理多版本 Python
python·macos·mac
IKaros_α‌1 天前
mac上安装openclaw从入门到删除
macos
x-cmd1 天前
macOS 内存模型深度解析 | x free 设计哲学
linux·macos·内存·策略模式·free·x-cmd
itinymeng1 天前
在 macOS 上遇到 brew: command not found 错误,通常是因为 ‌Homebrew 未安装‌ 或 ‌PATH 环境变量未正确配置‌
macos
oscar9991 天前
Claude Code 的“计算机使用”功能:让命令行助手真正操控macOS桌面
macos·claude code·computer
老兵发新帖2 天前
软件开发国内常用镜像源配置及回退方法(MAC版)
macos·软件工程
qq_411262422 天前
ESP32-C5 软件配置MAC 地址
macos
鸠摩智首席音效师2 天前
如何在 MacOS 上安装 PostgreSQL ?
数据库·macos·postgresql
花千树-0102 天前
IndexTTS2 在 macOS 性能最佳设置(M1/M2/M3/M4 全适用)
人工智能·深度学习·macos·ai·语音识别·ai编程