linux使用split命令来实现文件的分割,分割方式分为按照行数和大小。
使用的文件大小如下所示:
[root@node1 ~]# ll -h split.csv
-rw-r--r-- 1 root root 368M Apr 16 11:32 split.csv
1.按照行数进行分割
使用参数-l则是按照行数进行分割,例如以100000行进行分割:
[root@node1 split]# split -l 100000 split.csv
[root@node1 split]# ll
total 753120
-rw-r--r-- 1 root root 385565005 Apr 16 11:32 split.csv
-rw-r--r-- 1 root root 13227820 Apr 16 11:49 xaa
-rw-r--r-- 1 root root 13312229 Apr 16 11:49 xab
-rw-r--r-- 1 root root 13334281 Apr 16 11:49 xac
-rw-r--r-- 1 root root 13340551 Apr 16 11:49 xad
-rw-r--r-- 1 root root 13328378 Apr 16 11:49 xae
-rw-r--r-- 1 root root 13328644 Apr 16 11:49 xaf
-rw-r--r-- 1 root root 13329205 Apr 16 11:49 xag
-rw-r--r-- 1 root root 13342191 Apr 16 11:49 xah
-rw-r--r-- 1 root root 13335065 Apr 16 11:49 xai
-rw-r--r-- 1 root root 13340995 Apr 16 11:49 xaj
-rw-r--r-- 1 root root 13329364 Apr 16 11:49 xak
-rw-r--r-- 1 root root 13335465 Apr 16 11:49 xal
-rw-r--r-- 1 root root 13434160 Apr 16 11:49 xam
-rw-r--r-- 1 root root 13428322 Apr 16 11:49 xan
-rw-r--r-- 1 root root 13430440 Apr 16 11:49 xao
-rw-r--r-- 1 root root 13436362 Apr 16 11:49 xap
-rw-r--r-- 1 root root 13427959 Apr 16 11:49 xaq
-rw-r--r-- 1 root root 13432646 Apr 16 11:49 xar
-rw-r--r-- 1 root root 13427024 Apr 16 11:49 xas
-rw-r--r-- 1 root root 13426089 Apr 16 11:49 xat
-rw-r--r-- 1 root root 13427901 Apr 16 11:49 xau
-rw-r--r-- 1 root root 13430607 Apr 16 11:49 xav
-rw-r--r-- 1 root root 13424609 Apr 16 11:49 xaw
-rw-r--r-- 1 root root 13432881 Apr 16 11:49 xax
-rw-r--r-- 1 root root 13431539 Apr 16 11:49 xay
-rw-r--r-- 1 root root 13428560 Apr 16 11:49 xaz
-rw-r--r-- 1 root root 13425964 Apr 16 11:49 xba
-rw-r--r-- 1 root root 13436463 Apr 16 11:49 xbb
-rw-r--r-- 1 root root 10799291 Apr 16 11:49 xbc
可在命令的最后加上想要的文件开头名,例如以split开头:
[root@node1 split]# split -l 100000 split.csv split
[root@node1 split]# ll
total 753120
-rw-r--r-- 1 root root 13227820 Apr 16 11:51 splitaa
-rw-r--r-- 1 root root 13312229 Apr 16 11:51 splitab
-rw-r--r-- 1 root root 13334281 Apr 16 11:51 splitac
-rw-r--r-- 1 root root 13340551 Apr 16 11:51 splitad
-rw-r--r-- 1 root root 13328378 Apr 16 11:51 splitae
-rw-r--r-- 1 root root 13328644 Apr 16 11:51 splitaf
-rw-r--r-- 1 root root 13329205 Apr 16 11:51 splitag
-rw-r--r-- 1 root root 13342191 Apr 16 11:51 splitah
-rw-r--r-- 1 root root 13335065 Apr 16 11:51 splitai
-rw-r--r-- 1 root root 13340995 Apr 16 11:51 splitaj
-rw-r--r-- 1 root root 13329364 Apr 16 11:51 splitak
-rw-r--r-- 1 root root 13335465 Apr 16 11:51 splital
-rw-r--r-- 1 root root 13434160 Apr 16 11:51 splitam
-rw-r--r-- 1 root root 13428322 Apr 16 11:51 splitan
-rw-r--r-- 1 root root 13430440 Apr 16 11:51 splitao
-rw-r--r-- 1 root root 13436362 Apr 16 11:51 splitap
-rw-r--r-- 1 root root 13427959 Apr 16 11:51 splitaq
-rw-r--r-- 1 root root 13432646 Apr 16 11:51 splitar
-rw-r--r-- 1 root root 13427024 Apr 16 11:51 splitas
-rw-r--r-- 1 root root 13426089 Apr 16 11:51 splitat
-rw-r--r-- 1 root root 13427901 Apr 16 11:51 splitau
-rw-r--r-- 1 root root 13430607 Apr 16 11:51 splitav
-rw-r--r-- 1 root root 13424609 Apr 16 11:51 splitaw
-rw-r--r-- 1 root root 13432881 Apr 16 11:51 splitax
-rw-r--r-- 1 root root 13431539 Apr 16 11:51 splitay
-rw-r--r-- 1 root root 13428560 Apr 16 11:51 splitaz
-rw-r--r-- 1 root root 13425964 Apr 16 11:51 splitba
-rw-r--r-- 1 root root 13436463 Apr 16 11:51 splitbb
-rw-r--r-- 1 root root 10799291 Apr 16 11:51 splitbc
-rw-r--r-- 1 root root 385565005 Apr 16 11:32 split.csv
2.按照大小进行分割
使用参数-b则是按照行数进行分割,例如以128M进行分割:
[root@node1 split]# split -b 128M split.csv
[root@node1 split]# ll
total 753064
-rw-r--r-- 1 root root 385565005 Apr 16 11:32 split.csv
-rw-r--r-- 1 root root 134217728 Apr 16 14:18 xaa
-rw-r--r-- 1 root root 134217728 Apr 16 14:18 xab
-rw-r--r-- 1 root root 117129549 Apr 16 14:18 xac
命令后跟自己想要的命名,例如以split_开头:
[root@node1 split]# split -b 128M split.csv split_
[root@node1 split]# ll
total 1129596
-rw-r--r-- 1 root root 134217728 Apr 16 14:19 split_aa
-rw-r--r-- 1 root root 134217728 Apr 16 14:19 split_ab
-rw-r--r-- 1 root root 117129549 Apr 16 14:19 split_ac
-rw-r--r-- 1 root root 385565005 Apr 16 11:32 split.csv