zoukankan      html  css  js  c++  java
  • 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/
    /	/' > 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
  • 相关阅读:
    Python 面向对象(下)
    Python 面向对象(上)
    《面向对象程序设计概述》 牛咏梅
    lastIndexOf is not a function
    oracle lpad 函数使用介绍
    oracle中length、lengthb、substr、substrb用法小结
    oracle获取字符串长度函数length()和hengthb()
    js获取当前日期时间
    win7系统下查看端口的占用情况以及如何删除端口进程
    IntelliJ IDEA “Finds duplicated code”提示如何关闭
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14973507.html
Copyright © 2011-2022 走看看