split
文本处理
用法
split -l 1000 [file] [prefix]把文件切成若干块;表头只留在第一块里,文件名以 aa、ab 结尾,除非用 -d 改成数字。
常用选项
| 选项 | 含义 |
|---|---|
| -l | How many lines per output file |
| -b | How many bytes per file, with suffixes such as 50M |
| -n | Cut into this many roughly equal pieces |
| -d | Number the pieces instead of naming them aa, ab |
| -a | How many characters the suffix has |
| --additional-suffix | GNU: 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.tarPuts the pieces back together.
它们本来就是用管道串起来用的。串三条往往比让一条命令做完所有事更短。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. split 是做什么的?
把文件切成若干块;表头只留在第一块里,文件名以 aa、ab 结尾,除非用 -d 改成数字。
Q. 怎么写?
split -l 1000 [file] [prefix] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man split。这条命令属于文本处理。
相关命令
man 手册: man split