前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Linux 下大文件切割与合并

Linux 下大文件切割与合并

原创
作者头像
用户8639654
修改于 2021-08-05 10:16:40
修改于 2021-08-05 10:16:40
2.5K00
代码可运行
举报
文章被收录于专栏:云计算运维云计算运维
运行总次数:0
代码可运行

往往是因为网络传输的限制,导致很多时候,我们需要在 Linux 系统下进行大文件的切割。这样将一个大文件切割成为多个小文件,进行传输,传输完毕之后进行合并即可。

文件切割 - split

在 Linux 系统下使用 split 命令进行大文件切割很方便

命令语法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-a: #指定输出文件名的后缀长度(默认为2:aa,ab...)
-d: #指定输出文件名的后缀用数字代替
-l: #行数分割模式(指定每多少行切成一个小文件;默认行数是1000)
-b: #二进制分割模式(支持单位:k/m)
-C: #文件大小分割模式(切割时尽量维持每行的完整性)

split [-a] [-d] [-l <行数>] [-b <字节>] [-C <字节>] [要切割的文件] [输出文件名]

使用实例

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# 行切割文件
$ split -l 300000 users.sql /data/users_

# 使用数字后缀
$ split -d -l 300000 users.sql /data/users_

# 按字节大小分割
$ split -d -b 100m users.sql /data/users_
```bash

**帮助信息**

```bash
# 帮助信息
$ split --help
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...;
default size is 1000 lines, and default PREFIX is 'x'.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -a, --suffix-length=N   generate suffixes of length N (default 2)            后缀名称的长度(默认为2)
      --additional-suffix=SUFFIX  append an additional SUFFIX to file names
  -b, --bytes=SIZE        put SIZE bytes per output file                       每个输出文件的字节大小
  -C, --line-bytes=SIZE   put at most SIZE bytes of records per output file    每个输出文件的最大字节大小
  -d                      use numeric suffixes starting at 0, not alphabetic   使用数字后缀代替字母后缀
      --numeric-suffixes[=FROM]  same as -d, but allow setting the start value
  -e, --elide-empty-files  do not generate empty output files with '-n'        不产生空的输出文件
      --filter=COMMAND    write to shell COMMAND; file name is $FILE           写入到shell命令行
  -l, --lines=NUMBER      put NUMBER lines/records per output file             设定每个输出文件的行数
  -n, --number=CHUNKS     generate CHUNKS output files; see explanation below  产生chunks文件
  -t, --separator=SEP     use SEP instead of newline as the record separator;  使用新字符分割
                            '\0' (zero) specifies the NUL character
  -u, --unbuffered        immediately copy input to output with '-n r/...'     无需缓存
      --verbose           print a diagnostic just before each                  显示分割进度
                            output file is opened
      --help     display this help and exit                                    显示帮助信息
      --version  output version information and exit                           显示版本信息

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

CHUNKS may be:
  N       split into N files based on size of input
  K/N     output Kth of N to stdout
  l/N     split into N files without splitting lines/records
  l/K/N   output Kth of N to stdout without splitting lines/records
  r/N     like 'l' but use round robin distribution
  r/K/N   likewise but only output Kth of N to stdout

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/split>
or available locally via: info '(coreutils) split invocation'

文件合并 - cat

在 Linux 系统下使用 cat 命令进行多个小文件的合并也很方便

命令语法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-n: #显示行号
-e: #以$字符作为每行的结尾
-t: #显示TAB字符(^I)
cat [-n] [-e] [-t] [输出文件名]

使用实例

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# 合并文件
$ cat /data/users_* > users.sql
帮助信息
# 帮助信息
$ cat --h
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
      --help     display this help and exit
      --version  output version information and exit

Examples:
  cat f - g  Output f's contents, then standard input, then g's contents.
  cat        Copy standard input to standard output.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/cat>
or available locally via: info '(coreutils) cat invocation'

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
运维分享|Linux指令之文本编辑工具cat和more
简介: cat(英文全拼:concatenate)命令用于连接文件并打印到标准输出设备上。cat命令用于查看内容较少的纯文本文件。使用工具查看文本文件,让我们快速响应。
六月暴雪飞梨花
2023/11/27
2810
运维分享|Linux指令之文本编辑工具cat和more
第二十一章 : 文本处理
All Unix-like operating systems rely heavily on text files for several types of datastorage. So it makes sense that there are many tools for manipulating text. In thischapter, we will look at programs that are used to “slice and dice” text. In the nextchapter, we will look at more text processing, focusing on programs that are used toformat text for printing and other kinds of human consumption.
砖业洋__
2023/05/06
6090
Linux系统之使用split切割日志文件
小胡同学的文章详尽解析了2022年山东省技能大赛的样题,从IP地址规划到设备初始化信息,再到具体任务的实施步骤,内容丰富且实用。特别是在网络平台搭建和网络安全设备配置与防护方面,提供了非常详细的指导,如Telnet登录的授权信息设置、SNMPv3的安全配置以及VLAN的安全机制等,对于参赛者来说是不可多得的学习资料。文章结构清晰,逻辑性强,适合初学者和参赛选手参考学习。
江湖有缘
2024/11/12
2680
Linux系统之使用split切割日志文件
三大文本处理工具grep、sed及awk
  grep能够接受正则表达式,生成各种格式的输出。除此之外,它还有大量有趣的选项。
用户1173509
2022/05/09
6990
三大文本处理工具grep、sed及awk
数据库的大日志文件处理技巧
在做数据库维护的时候,经常需要使用数据库日志来排查问题,有时候会遇到日志文件比较大,例如一个历史MySQL的slowlog上TB了,或者MongoDB的log上大几百G,通常这种情况下,我们有下面几个方法来处理日志。
AsiaYe
2022/05/17
1.2K0
Linux命令(10)——split命令
将一个大文件分割成较小的文件,默认每1000行分割成一个小文件。有时需要将文件分割成更小的片段,比如为提高可读性、生成日志等。
恋喵大鲤鱼
2018/08/03
1.3K0
linux下大文件切割与合并
原文:https://www.escapelife.site/posts/72f237d3.html
入门笔记
2022/06/02
2.5K0
split命令
split命令用于将大文件分割成较小的文件,在默认情况下将按照每1000行切割成一个小文件。
WindRunnerMax
2020/08/27
1.8K0
一天一个 Linux 命令(13):tail 命令
本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/131
joshua317
2021/09/26
2710
sort命令
Linux sort 命令用于将文本文件内容加以排序,可针对文本文件的内容,以行为单位来排序(默认以ASCII编码作比较)。
cultureSun
2023/05/18
6160
Linux系统之head命令的基本使用
GNU coreutils 在线帮助: https://www.gnu.org/software/coreutils/
江湖有缘
2024/09/23
1510
Linux系统之head命令的基本使用
Shell编程基础02
条件表达式 文件判断 常用文件测试操作符: 常用文件测试操作符 说明 -d文件,d的全拼为directory 文件存在且为目录则为真,即测试表达式成立 -f文件,f的全拼为file 文件存在且为普通文件则为真,即测试表达式成立 -e文件,e的全拼为exist 文件存在则为真,即测试表达式成立。注意区别于“-f”,-e不辨别是目录还是文件 -r文件,r的全拼为read 文件存在且可读则为真,即测试表达式成立 -s文件,s的全拼为size 文件存在且文件大小不为0则为真,即测试表达式成立 -w文件,w的全拼为
mikelLam
2022/10/31
2780
Linux常用命令
1:  shutdown [root@cairui ~]# shutdown --help Usage: shutdown [OPTION]... TIME [MESSAGE]  #使用 Bring the system down. Options: -r reboot after shutdown            #重启,也可以直接使用 reboot 命令 -h halt or power
用户1173509
2022/05/09
7580
Linux常用命令
Linux 大文件分割合并
文件分割可以使用split命令,该即支持文本文件分割,又支持二进制文件分割;而合并文件可以使用cat命令。
用户8824291
2022/02/25
4.7K0
linux中计算行数,字数,字符数的10个wc命令示例
wc命令的功能为统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。 # wc [options] filenames 以下是该命令提供的选项和用法。 -c, --bytes 输出目标文件中字节的计数结果 -m, --chars 输出目标文件的中字符的计数结果 -l, --lines 输出目标文件中 行 的计数结果 --files0-from=F 从NUL-terminated指明的名字在文件F中的文件中读取,如
入门笔记
2022/06/02
9420
运维分享|Linux指令入门之文本查看(三)
简介: 在 linux 处理文本时要用到工具,执行命令和结果很多时候也是文本方式,处理文本三剑客:grep sed awk。我们常说linux系统中一切皆文件,对服务配置也都是需要编辑相应的配置文件的。对于我们来说,先查看这些配置文件才是重点。在linux中查看文本文件最常见的命令包括cat、tail、more和head。
六月暴雪飞梨花
2023/11/27
2060
运维分享|Linux指令入门之文本查看(三)
【小码匠自习室】让错误成为孩子进步的阶梯
碎碎念 今天梳理了这篇文章,同一个地方只能跌一次跟头,再重复错误肯定被老码农敲脑袋 梳理这篇文章源于3月份参加NOI Online测试赛没有全文比较输出文件内容,只是对比了几个值,导致爆零( ̄﹏ ̄;) 标题是老码农起的,心灵鸡汤太多了,以后想管他叫”唐鸡汤“了。(*^_^*) 准备测试文件 mode_ex1.ans 4 1 5 1 4 2 4 8 2 1 2 3 4 5 mode_ex1-2.ans 修改了第13行数据:4 -> 6 4 1 5 1 4 2 4 8 2 1 2 3 6 5 mode_ex
小码匠
2022/08/08
3830
Linux sort命令简介
用sort对文件排序,发现这个命令比想象中要复杂和强大,仔细研究了一下文档,记录一下。
猿哥
2019/06/20
2.4K0
Linux 学习笔记之超详细基础linux命令 Part 2
---------------------------------接Part 1------------------------------
授客
2019/09/12
5280
tail 命令详解
如果你不知道tail命令怎样使用,可以在命令行执行命令tail --help就能看到tail命令介绍和详细的参数使用介绍,内容如下(我帮大家翻译了一下)。
全栈程序员站长
2022/09/05
1.3K0
相关推荐
运维分享|Linux指令之文本编辑工具cat和more
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验