split
壓縮與傳輸
用法
split -b <size> <file> <prefix>把大檔案切成好幾塊;預設是按行切、每 1000 行一塊,想按大小切就得寫 `-b 100M`,不給前綴時碎片叫 xaa、xab,拼回去只用一句 `cat part_* > file`,而這能成立全靠後綴本身是有序的。
常用選項
| 選項 | 含義 |
|---|---|
| -b 100M | Pieces of a fixed size; K, M and G suffixes work on both platforms. |
| -l 1000 | Split by line count instead, which is the default behaviour at 1000 lines. |
| -n 4 | Cut into exactly four pieces. |
| -d | Numeric suffixes instead of aa, ab, ac. |
| -a 3 | Suffix length, when two letters are not enough. |
| --additional-suffix=.part | Append 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.gzReassemble 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