Linux fallocate split yes 切割文件实例

本文介绍了如何使用Linux的fallocate和split命令进行文件切割,包括按文件大小、行数和数量进行切割。通过实例展示了不同切割方式的输出结果,并探讨了如何避免生成0长度的文件。这对于管理和处理大型文件非常实用。

Linux fallocate split yes 切割文件实例
【按文件大小切割】
fallocate -l 20MB myfile
split -b 2MB myfile
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xaa
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xab
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xac
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xad
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xae
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xaf
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xag
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xah
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xai
-rw-rw-r-- 1 hehe hehe 2.0M Oct  1 00:15 xaj
【按文件行数切割】
yes "this is a test file" | head -c 10k > numfile
split -l 100 numfile split_file_
-rw-rw-r-- 1 hehe hehe 2.0K Oct  1 02:25 split_file_aa
-rw-rw-r-- 1 hehe hehe 2.0K Oct  1 02:25 split_file_ab
-rw-rw-r-- 1 hehe hehe 2.0K Oct  1 02:25 split_file_ac
-rw-rw-r-- 1 hehe hehe 2.0K Oct  1 02:25 split_file_ad
-rw-rw-r-- 1 hehe hehe 2.0K Oct  1 02:25 split_file_ae
-rw-rw-r-- 1 hehe hehe  240 Oct  1 02:25 split_file_af
【按文件数量切割】
fallocate -l 50M cntfile
split -d -n 5 cntfile
-rw-rw-r-- 1 hehe hehe  10M Oct  1 06:54 x00
-rw-rw-r-- 1 hehe hehe  10M Oct  1 06:54 x01
-rw-rw-r-- 1 hehe hehe  10M Oct  1 06:54 x02
-rw-rw-r-- 1 hehe hehe  10M Oct  1 06:54 x03
-rw-rw-r-- 1 hehe hehe  10M Oct  1 06:54 x04
【禁止生成 0 长度的文件】
fallocate -l 5 testfile
split --verbose -n 8 testfile
-rw-rw-r-- 1 hehe hehe    1 Oct  2 20:03 xaa
-rw-rw-r-- 1 hehe hehe    1 Oct  2 20:03 xab
-rw-rw-r-- 1 hehe hehe    1 Oct  2 20:03 xac
-rw-rw-r-- 1 hehe hehe    1 Oct  2 20:03 xad
-rw-rw-r-- 1 hehe hehe    1 Oct  2 20:03 xae
-rw-rw-r-- 1 hehe hehe    0 Oct  2 20:03 xaf
-rw-rw-r-- 1 hehe hehe    0 Oct  2 20:03 xag
-rw-rw-r-- 1 hehe hehe    0 Oct  2 20:03 xah
rm -f xa[a-h]
split --verbose -e -n 8 testfile
creating file ‘xaa’
creating file ‘xab’
creating file ‘xac’
creating file ‘xad’
creating file ‘xae’
-rw-rw-r-- 1 hehe hehe    1 Oct  1 00:07 xaa
-rw-rw-r-- 1 hehe hehe    1 Oct  1 00:07 xab
-rw-rw-r-- 1 hehe hehe    1 Oct  1 00:07 xac
-rw-rw-r-- 1 hehe hehe    1 Oct  1 00:07 xad
-rw-rw-r-- 1 hehe hehe    1 Oct  1 00:07 xae

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值