linux命令之split
1.split介绍
linux命令split是按照指定的大小或行数分割文件。输出文件名为“前缀aa”、“前缀ab”。默认前缀以“x”开头,默认文件大小为1000行
2.split用法
split [参数] filename [前缀]
split参数
参数 | 说明 |
-l | 指定输出文件有多少行 |
-a | 指定长度的后缀,默认:2 |
-b | 指定输出文件的大小,默认:字节 |
--verbose | 显示详细输出 |
3.实例
3.1.默认分割文件
命令:
split ztj.log
[root@rhel77 ztj.bak]# ls -l ztj.log
-rw-r--r-- 1 root root 81141 Nov 8 08:55 ztj.log
[root@rhel77 ztj.bak]# split ztj.log
[root@rhel77 ztj.bak]# ls
xaa xab(输出文件名为"前缀aa"、"前缀ab"且默认前缀为"x") ztj.log
[root@rhel77 ztj.bak]#
[root@rhel77 ztj.bak]# wc -l xaa
1000 xaa(默认大小为1000行)
[root@rhel77 ztj.bak]# wc -l xab
682 xab(最后文件小于1000行,就全部显示)
[root@rhel77 ztj.bak]#
3.2.分割文件,设置行数为500行
命令:
split -l 500 ztj.log
[root@rhel77 ztj.bak]# split -l 500 ztj.log
[root@rhel77 ztj.bak]# ls
xaa xab xac xad ztj.log
[root@rhel77 ztj.bak]# wc -l xaa
500 xaa
[root@rhel77 ztj.bak]# wc -l xab
500 xab
[root@rhel77 ztj.bak]# wc -l xac
500 xac
[root@rhel77 ztj.bak]# wc -l xad
182 xad
[root@rhel77 ztj.bak]#
3.3.分割文件,设置后缀长度为5
命令:
split -a 5 ztj.log
[root@rhel77 ztj.bak]# split -a 5 ztj.log
[root@rhel77 ztj.bak]# ls
xaaaaa xaaaab ztj.log
[root@rhel77 ztj.bak]# wc -l xaaaaa
1000 xaaaaa
[root@rhel77 ztj.bak]# wc -l xaaaab
682 xaaaab
[root@rhel77 ztj.bak]#
3.4.分割文件,设置文件大小为2000字节,并显示详细输出
命令:
split --verbose -b 2000 ztj.log
[root@rhel77 ztj.bak]# split --verbose -b 2000 ztj.log
creating file ‘xaa’
creating file ‘xab’
creating file ‘xac’
creating file ‘xad’
creating file ‘xae’
creating file ‘xaf’
creating file ‘xag’
creating file ‘xah’
creating file ‘xai’
creating file ‘xaj’
creating file ‘xak’
creating file ‘xal’
creating file ‘xam’
creating file ‘xan’
creating file ‘xao’
creating file ‘xap’
creating file ‘xaq’
creating file ‘xar’
creating file ‘xas’
creating file ‘xat’
creating file ‘xau’
creating file ‘xav’
creating file ‘xaw’
creating file ‘xax’
creating file ‘xay’
creating file ‘xaz’
creating file ‘xba’
creating file ‘xbb’
creating file ‘xbc’
creating file ‘xbd’
creating file ‘xbe’
creating file ‘xbf’
creating file ‘xbg’
creating file ‘xbh’
creating file ‘xbi’
creating file ‘xbj’
creating file ‘xbk’
creating file ‘xbl’
creating file ‘xbm’
creating file ‘xbn’
creating file ‘xbo’
[root@rhel77 ztj.bak]#
[root@rhel77 ztj.bak]# ls
xac xaf xai xal xao xar xau xax xba xbd xbg xbj xbm ztj.log
xaa xad xag xaj xam xap xas xav xay xbb xbe xbh xbk xbn
xab xae xah xak xan xaq xat xaw xaz xbc xbf xbi xbl xbo
3.5.分割文件,设置文件前缀为test
命令:
split -l 1000 ztj.log test
[root@rhel77 ztj.bak]# split -l 1000 ztj.log test
[root@rhel77 ztj.bak]# ls
testaa testab ztj.log
[root@rhel77 ztj.bak]# wc -l testaa
1000 testaa
[root@rhel77 ztj.bak]# wc -l testab
682 testab
[root@rhel77 ztj.bak]#
标签:creating,ztj,rhel77,117,split,file,Linux,root,bak
From: https://blog.51cto.com/ztj1216/8320705