首页·终端命令

split

文本处理

用法

split -l 1000 [file] [prefix]

把文件切成若干块;表头只留在第一块里,文件名以 aa、ab 结尾,除非用 -d 改成数字。

常用选项

选项含义
-lHow many lines per output file
-bHow many bytes per file, with suffixes such as 50M
-nCut into this many roughly equal pieces
-dNumber the pieces instead of naming them aa, ab
-aHow many characters the suffix has
--additional-suffixGNU: give every piece an extension

示例

split -l 1000 big.csv part_

Files part_aa, part_ab, 1000 lines each.

split -b 50M archive.tar chunk_

Pieces of 50 MB.

cat chunk_* > archive.tar

Puts the pieces back together.

它们本来就是用管道串起来用的。串三条往往比让一条命令做完所有事更短。

怎么看

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

常见问题

Q. split 是做什么的?

把文件切成若干块;表头只留在第一块里,文件名以 aa、ab 结尾,除非用 -d 改成数字。

Q. 怎么写?

split -l 1000 [file] [prefix] —— 方括号表示可以省略的部分。

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

这里列了 6 个,完整列表在 man split。这条命令属于文本处理。

相关命令

man 手册: man split