inux split 命令
功能说明:切割文件。
-a, --suffix-length=N use suffixes of length N (default 2) 指定拆分文件的后缀长度 -b, --bytes=SIZE put SIZE bytes per output file 按字节拆分,默认单位字节 -C, --line-bytes=SIZE put at most SIZE bytes of lines per output file 指定单行的最大大小,默认单位字节 -d, --numeric-suffixes use numeric suffixes instead of alphabetic 用数字作为拆分文件的后缀 -l, --lines=NUMBER put NUMBER lines per output file 按行数进行拆分
例如将一个为10行test.csv文件分成前缀为 test_ 的1行的个小文件,后缀为系数形式,且后缀为4位数字形式
先利用
wc -l test.csv #读出文件有多少行
再利用 split 命令
split -l 1 test.csv -d -a 1 test_
这里参数-l是每个小文件的行数,最大不能超过要分割文件的行数,后面接要分割的文件,-d 是指系数是数字而不是字母 -a 是指系数是四位数。而后面test_是系数的前缀。
结果:
-rw-r--r--. 1 root root 2 6月 24 08:39 test_0
-rw-r--r--. 1 root root 2 6月 24 08:39 test_1
-rw-r--r--. 1 root root 2 6月 24 08:39 test_2
-rw-r--r--. 1 root root 2 6月 24 08:39 test_3
-rw-r--r--. 1 root root 2 6月 24 08:39 test_4
-rw-r--r--. 1 root root 2 6月 24 08:39 test_5
-rw-r--r--. 1 root root 2 6月 24 08:39 test_6
-rw-r--r--. 1 root root 2 6月 24 08:39 test_7
-rw-r--r--. 1 root root 2 6月 24 08:39 test_8
-rw-r--r--. 1 root root 2 6月 24 08:39 test_9