linux系统中split命令

1、split按文件大小拆分文件

测试数据如下:

[root@centos79 test]# dd if=/dev/zero bs=1M count=100 of=a.txt
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.0620975 s, 1.7 GB/s
[root@centos79 test]# ll -h
total 100M
-rw-r--r--. 1 root root 100M Jul  5 17:17 a.txt

 

2、-b参数按照大小拆分文件

[root@centos79 test]# ls
a.txt
[root@centos79 test]# split -b 50M a.txt
[root@centos79 test]# ll -h
total 200M
-rw-r--r--. 1 root root 100M Jul  5 17:17 a.txt
-rw-r--r--. 1 root root  50M Jul  5 17:19 xaa
-rw-r--r--. 1 root root  50M Jul  5 17:19 xab

 

3、利用cat命令合并拆分的文件

复制代码
[root@centos79 test]# cat xaa xab > b.txt
[root@centos79 test]# ll -h
total 300M
-rw-r--r--. 1 root root 100M Jul  5 17:17 a.txt
-rw-r--r--. 1 root root 100M Jul  5 17:20 b.txt
-rw-r--r--. 1 root root  50M Jul  5 17:19 xaa
-rw-r--r--. 1 root root  50M Jul  5 17:19 xab
[root@centos79 test]# md5sum *
2f282b84e7e608d5852449ed940bfc51  a.txt
2f282b84e7e608d5852449ed940bfc51  b.txt
25e317773f308e446cc84c503a6d1f85  xaa
25e317773f308e446cc84c503a6d1f85  xab
复制代码

 

5、给拆分后的文件增加前缀

复制代码
[root@centos79 test]# rm !(a.txt)
[root@centos79 test]# ls
a.txt
[root@centos79 test]# split -b 50M a.txt sub_
[root@centos79 test]# ls
a.txt  sub_aa  sub_ab
[root@centos79 test]# ll -h
total 200M
-rw-r--r--. 1 root root 100M Jul  5 17:17 a.txt
-rw-r--r--. 1 root root  50M Jul  5 17:22 sub_aa
-rw-r--r--. 1 root root  50M Jul  5 17:22 sub_ab
复制代码

 

6、使用-d参数给拆分后的文件指定00、01……后缀

复制代码
[root@centos79 test]# rm !(a.txt)
[root@centos79 test]# ls
a.txt
[root@centos79 test]# split -b 50M a.txt sub_ -d
[root@centos79 test]# ls
a.txt  sub_00  sub_01
[root@centos79 test]# ll -h
total 200M
-rw-r--r--. 1 root root 100M Jul  5 17:17 a.txt
-rw-r--r--. 1 root root  50M Jul  5 17:25 sub_00
-rw-r--r--. 1 root root  50M Jul  5 17:25 sub_01
复制代码

 

7、按行拆分文件

测试数据如下:

复制代码
[root@centos79 test]# seq -f %02g 20 | sed = | sed 'N;s/\n/\t/' > a.txt
[root@centos79 test]# ls
a.txt
[root@centos79 test]# cat a.txt
1       01
2       02
3       03
4       04
5       05
6       06
7       07
8       08
9       09
10      10
11      11
12      12
13      13
14      14
15      15
16      16
17      17
18      18
19      19
20      20
复制代码

 

8、使用 -n或者 -l n进行按行拆分文件

复制代码
[root@centos79 test]# ls
a.txt
[root@centos79 test]# cat a.txt
1       01
2       02
3       03
4       04
5       05
6       06
7       07
8       08
9       09
10      10
11      11
12      12
13      13
14      14
15      15
16      16
17      17
18      18
19      19
20      20
[root@centos79 test]# split -l 5 a.txt sub_ -d     ## 按5行进行拆分文件
[root@centos79 test]# ls
a.txt  sub_00  sub_01  sub_02  sub_03
[root@centos79 test]# wc -l *
 20 a.txt
  5 sub_00
  5 sub_01
  5 sub_02
  5 sub_03
 40 total
[root@centos79 test]# cat sub_00
1       01
2       02
3       03
4       04
5       05
复制代码

 

posted @   小鲨鱼2018  阅读(322)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示