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
Linux fallocate split yes 切割文件实例
最新推荐文章于 2025-01-26 19:36:08 发布
本文介绍了如何使用Linux的fallocate和split命令进行文件切割,包括按文件大小、行数和数量进行切割。通过实例展示了不同切割方式的输出结果,并探讨了如何避免生成0长度的文件。这对于管理和处理大型文件非常实用。
707

被折叠的 条评论
为什么被折叠?



