split:分割文件

xiaohai 2021-06-08 11:17:51 1617人围观 标签: Linux 
简介split命令可以根据指定的行数或者指定的文件大小分割文件
说明

  split命令可以根据指定的行数或者指定的文件大小分割文件

格式

  split [option] [filename] [PREFIX]

PREFIX:输出文件名前缀

常用参数说明
  • -b:指定分割后文件的最大字节数
  • -l:指定分割后文件的最大行数
  • -a:指定后缀长度,默认为2个字母
  • -d:使用数字后缀
示例

1、指定行数进行分割

[root@localhost ~]# wc -l /apps/nginx/conf/nginx.conf
123 /apps/nginx/conf/nginx.conf

[root@localhost ~]# split -l 30 /apps/nginx/conf/nginx.conf nginx_

[root@localhost ~]# ll nginx_*
-rw-r--r--. 1 root root 619 Jun  4 01:24 nginx_aa
-rw-r--r--. 1 root root 670 Jun  4 01:24 nginx_ab
-rw-r--r--. 1 root root 990 Jun  4 01:24 nginx_ac
-rw-r--r--. 1 root root 677 Jun  4 01:24 nginx_ad
-rw-r--r--. 1 root root  10 Jun  4 01:24 nginx_ae

[root@localhost ~]# wc l nginx_*
wc: l: No such file or directory
  30   50  619 nginx_aa
  30   64  670 nginx_ab
  30   87  990 nginx_ac
  30   69  677 nginx_ad
   3    2   10 nginx_ae
 123  272 2966 total

2、指定后缀长度

[root@localhost ~]# split -l 30 -a 3 /apps/nginx/conf/nginx.conf nginx_
[root@localhost ~]# ll nginx_*
-rw-r--r--. 1 root root 619 Jun  4 01:27 nginx_aaa
-rw-r--r--. 1 root root 670 Jun  4 01:27 nginx_aab
-rw-r--r--. 1 root root 990 Jun  4 01:27 nginx_aac
-rw-r--r--. 1 root root 677 Jun  4 01:27 nginx_aad
-rw-r--r--. 1 root root  10 Jun  4 01:27 nginx_aae
[root@localhost ~]# wc l nginx_*
wc: l: No such file or directory
  30   50  619 nginx_aaa
  30   64  670 nginx_aab
  30   87  990 nginx_aac
  30   69  677 nginx_aad
   3    2   10 nginx_aae
 123  272 2966 total

3、使用数字后缀

[root@localhost ~]# split -l 30 -a 3 -d /apps/nginx/conf/nginx.conf nginx_
[root@localhost ~]# ll nginx_*
-rw-r--r--. 1 root root 619 Jun  4 01:27 nginx_000
-rw-r--r--. 1 root root 670 Jun  4 01:27 nginx_001
-rw-r--r--. 1 root root 990 Jun  4 01:27 nginx_002
-rw-r--r--. 1 root root 677 Jun  4 01:27 nginx_003
-rw-r--r--. 1 root root  10 Jun  4 01:27 nginx_004
[root@localhost ~]# wc l nginx_*
wc: l: No such file or directory
  30   50  619 nginx_000
  30   64  670 nginx_001
  30   87  990 nginx_002
  30   69  677 nginx_003
   3    2   10 nginx_004
 123  272 2966 total

4、按大小分割文件

[root@localhost ~]# split -b 1K -d  /apps/nginx/conf/nginx.conf nginx_ #1kb分割
[root@localhost ~]# ll nginx_*
-rw-r--r--. 1 root root 1024 Jun  4 01:29 nginx_00
-rw-r--r--. 1 root root 1024 Jun  4 01:29 nginx_01
-rw-r--r--. 1 root root  918 Jun  4 01:29 nginx_02