Linux split拆分文件
介绍
split可以将一个大文件拆分成指定大小的多个文件,并且拆分速度非常的快,拆分一个1G大小的文件花费不到1S的时间,如果手工在windows上面进行操作估计得卡死。
选项
Usage: split [OPTION]... [INPUT [PREFIX]] Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -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 按行数进行拆分 --verbose print a diagnostic just before each output file is opened --help display this help and exit --version output version information and exit SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y. 可以用后缀指定其它的单位 Report split bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'split invocation'
实例
[root@localhost test]# more test
a
b
c
d
e
f
g
1.根据行拆分
每3行拆分成一个文件,拆分后的文件名以name开头,以数字作为后缀后缀长度为1
split -l 3 test -d -a 1 name
[root@localhost test]# ll total 16 -rw-r--r--. 1 root root 6 Oct 9 19:12 name0 -rw-r--r--. 1 root root 6 Oct 9 19:12 name1 -rw-r--r--. 1 root root 2 Oct 9 19:12 name2 -rw-r--r--. 1 root root 14 Oct 9 19:07 test
2.按字节进行拆分
每三个字节拆分成一个文件,默认不加单位就是字节,也可以带单位比如KB,MB等
split -b 3 test -d -a 1 new
[root@localhost test]# ls -l new* -rw-r--r--. 1 root root 3 Oct 9 19:13 new0 -rw-r--r--. 1 root root 3 Oct 9 19:13 new1 -rw-r--r--. 1 root root 3 Oct 9 19:13 new2 -rw-r--r--. 1 root root 3 Oct 9 19:13 new3 -rw-r--r--. 1 root root 2 Oct 9 19:13 new4
总结
spit命令很实用,比如导入数据时将文件进行拆分并发导入会快很多。
备注: 作者:pursuer.chen 博客:http://www.cnblogs.com/chenmh 本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。 《欢迎交流讨论》 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2014-10-09 SQL Server 容易忽略的错误