首页·终端命令

split

压缩与传输

用法

split -b <size> <file> <prefix>

把大文件切成若干块;默认是按行切、每 1000 行一块,想按大小切就得写 `-b 100M`,不给前缀时碎片叫 xaa、xab,拼回去只用一句 `cat part_* > file`,而这能成立全靠后缀本身是有序的。

常用选项

选项含义
-b 100MPieces of a fixed size; K, M and G suffixes work on both platforms.
-l 1000Split by line count instead, which is the default behaviour at 1000 lines.
-n 4Cut into exactly four pieces.
-dNumeric suffixes instead of aa, ab, ac.
-a 3Suffix length, when two letters are not enough.
--additional-suffix=.partAppend an extension to each piece. GNU only.
<prefix>Optional, and without it the pieces are named xaa, xab, xac.

示例

split -b 100M big.tar.gz part_

Produces part_aa, part_ab and so on.

cat part_* > big.tar.gz

Reassemble in glob order, which is why the suffixes are sorted.

split -l 5000 -d data.csv chunk_

Five thousand lines per piece, with numeric suffixes.

打包和压缩是两件事:tar 打包,gzip 压小,.tar.gz 是两样一起。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. split 是做什么的?

把大文件切成若干块;默认是按行切、每 1000 行一块,想按大小切就得写 `-b 100M`,不给前缀时碎片叫 xaa、xab,拼回去只用一句 `cat part_* > file`,而这能成立全靠后缀本身是有序的。

Q. 怎么写?

split -b <size> <file> <prefix> —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 7 个,完整列表在 man split。这条命令属于压缩与传输。

相关命令

man 手册: man split