Linux文件切割命令——Split

前言

项目取数过程中遇见文件大小超过最大范围的时候,此时想着通过切割文件的方式来解决,最后找到了split命令,这里记录下来使用方法方便下次使用。

split命令参数

split [–help][–version][-<行数>][-b <字节>][-C <字节>][-l <行数>][-a [num]][要切割的文件][输出文件名]

  • 必须添加的参数 [切割参数:-/-l/l] [要切割的文件]

  • - & -l : 指定行数切割;

  • -b & -C : 指定大小切割,支持[K, M, G, T, P, E, Z], -C 切割时将尽量维持每行的完整性;

  • -d : 指定切割包的后缀为数字;

  • -a [NUM] : 设置后缀长度;(e.g. -a 2 --表示后缀长度为 2,在不指定后缀的情况下默认为小写英文字母)

  • [输出文件名] : 设置切割后文件的前置文件名,split 会自动在前置文件名后再加上编号

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 按照行数切割 test.xlsx
[root@sole ~]# split -300 -d -a 1 test.xlsx test.xlsx. # -d不加则是以a b c结尾 ,-a 1 设置了后缀的长度
[root@sole ~]# split -l 300 -d -a 1 test.xlsx test.xlsx.
# 按行切割效果
-rw-r--r-- 1 root root 186317 Sep 30 11:34 test.xlsx
-rw-r--r-- 1 root root 82185 Dec 31 15:52 test.xlsx.1
-rw-r--r-- 1 root root 62744 Dec 31 15:52 test.xlsx.2
-rw-r--r-- 1 root root 41388 Dec 31 15:52 test.xlsx.3


# 按照大小切割 test.xlsx
[root@sole test]# split -b 60K -d -a 1 test.xlsx test.xlsx.
[root@sole test]# split -C 60K -d -a 1 test.xlsx test.xlsx.

# -b切割效果
-rw-r--r-- 1 root root 182K Sep 30 11:34 test.xlsx
-rw-r--r-- 1 root root 60K Dec 31 15:56 test.xlsx.1
-rw-r--r-- 1 root root 60K Dec 31 15:56 test.xlsx.2
-rw-r--r-- 1 root root 60K Dec 31 15:56 test.xlsx.3
-rw-r--r-- 1 root root 2.0K Dec 31 15:56 test.xlsx.4
# -C 切割效果
-rw-r--r-- 1 root root 182K Sep 30 11:34 test.xlsx
-rw-r--r-- 1 root root 60K Dec 31 15:57 test.xlsx.1
-rw-r--r-- 1 root root 60K Dec 31 15:57 test.xlsx.2
-rw-r--r-- 1 root root 60K Dec 31 15:57 test.xlsx.3
-rw-r--r-- 1 root root 2.6K Dec 31 15:57 test.xlsx.4
-------------本文结束感谢您的阅读-------------