split --help
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 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
示例: 把一个大文件切分成小文件
cat split_file.sh
#!/bin/bash
#平均切分文件内容
#split_file.sh xx.txt
#传入文件
filename=$1
size=`du $filename | cut -f 1`
echo $size
#限制把文件切分为几份,暂时先按总文件大小/25M来切分
limit=`expr $size / 1024 / 25`
echo $limit
# 统计文件总行数
rows=`cat $filename | wc -l`
echo $rows
# 按多少行进行切分
line=`expr $rows / $limit`
echo $line
# 切分动作
split -l $line $filename -d $filename
# 切分前
ll
total 100368
-rw-r--r-- 1 omm wheel 102774656 Sep 5 2023 part-m-00000
#执行切分脚本
sh -x split_file.sh part-m-00000
# 切分后
ll
total 200740
-rw-r--r-- 1 omm wheel 102774656 Sep 5 2023 part-m-00000
-rw------- 1 omm wheel 34246315 Apr 19 20:11 part-m-000000
-rw------- 1 omm wheel 34237016 Apr 19 20:11 part-m-000001
-rw------- 1 omm wheel 34291325 Apr 19 20:11 part-m-000002
-rw------- 1 omm wheel 468 Apr 19 20:10 split_file.sh