CentOS 中用 Split 命令分割文件的方法

本文介绍如何在CentOS中使用split命令来高效地分割大文件。通过详细解释split命令的参数,例如指定后缀长度(-a)、设置每个文件大小(-b)等,帮助读者轻松掌握文件分割技巧。

CentOS 里切割大文件的命令如下:

NAME
       split - split a file into pieces
SYNOPSIS
       split [OPTION]... [INPUT [PREFIX]]
DESCRIPTION
       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
              generate suffixes of length N (default 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 lines per output file
       -d, --numeric-suffixes[=FROM]
              use numeric suffixes instead of alphabetic; FROM changes the start value (default 0)
       -e, --elide-empty-files
              do not generate empty output files with '-n'
       --filter=COMMAND
              write to shell COMMAND; file name is $FILE
       -l, --lines=NUMBER
              put NUMBER lines per output file
       -n, --number=CHUNKS
              generate CHUNKS output files; see explanation below
       -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

常用选项说明如下:

  • -a : 指定后缀长度
  • -b : 每个文件多少字节
  • -d : 使用数字后缀而不是字母
  • -l : 指定每个文件的行数

比如我想让后缀长度为 2,即 -a 2。用数字后缀 -d。每个文件 10M,即 -b 10m。命令可以设计如下:

  1. split -a 2 -d -b 10m /var/lib/mysql/general.log nowamagic 

会在 /root 文件夹下生成下面的切割文件:

  1. nowamagic00 
  2. nowamagic01 
  3. nowamagic02 
  4. nowamagic03 
  5. nowamagic04 
  6. nowamagic05 
  7. nowamagic06 
  8. nowamagic07 
  9. nowamagic08 
  10. nowamagic09 

除了最后一个文件不是10M(有可能恰好10M,不过几率很小),其它都是。


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值