Linux‎ > ‎

split and reassemble files on linux

Thank you for visiting this page, this page has been update in another link Split and reassemble files on linux
Here is a simple of split and reassemble case.
split -b 1048576 postgresql-8.3-A4.pdf pg83
$ls pg*
pg83aa  pg83ab  pg83ac  pg83ad  pg83ae  pg83af  pg83ag  pg83ah  pg83ai  pg83aj  pg83ak  pg83al  pg83am  pg83an  pg83ao  pg83ap

$cat pg83* >pg83.pdf

$md5sum pg83.pdf

de2308396abfda7c38929c31cf796315  pg83.pdf

$md5sum postgresql-8.3-A4.pdf
de2308396abfda7c38929c31cf796315  postgresql-8.3-A4.pdf

Split is a simple linux command, also available on other systems.
       split - split a file into pieces

       split [OPTION]... [INPUT [PREFIX]]

-a, -b and -d options
       -a, --suffix-length=N
              use suffixes of length N (default 2)
       -b, --bytes=SIZE
              put SIZE bytes per output file
       -d, --numeric-suffixes
              use numeric suffixes instead of alphabetic

$split -a3 -b 1048576 postgresql-8.3-A4.pdf pg83
$ls pg83*
pg83aaa  pg83aab  pg83aac  pg83aad  pg83aae  pg83aaf  pg83aag  pg83aah  pg83aai  pg83aaj  pg83aak  pg83aal  pg83aam  pg83aan  pg83aao  pg83aap

$rm -f pg83*

$split -a3 -b 1048576 -d postgresql-8.3-A4.pdf pg83
$ls pg83*
pg83000  pg83001  pg83002  pg83003  pg83004  pg83005  pg83006  pg83007  pg83008  pg83009  pg83010  pg83011  pg83012  pg83013  pg83014  pg83015

-l option, very useful for text file
       -l, --lines=NUMBER
              put NUMBER lines per output file

$split -a3 -l 10000 -d  newfilesvo splittest
$ls splittest0*
splittest000  splittest005  splittest010  splittest015  splittest020  splittest025  splittest030  splittest035  splittest040  splittest045  splittest050
splittest001  splittest006  splittest011  splittest016  splittest021  splittest026  splittest031  splittest036  splittest041  splittest046  splittest051
splittest002  splittest007  splittest012  splittest017  splittest022  splittest027  splittest032  splittest037  splittest042  splittest047  splittest052
splittest003  splittest008  splittest013  splittest018  splittest023  splittest028  splittest033  splittest038  splittest043  splittest048  splittest053
splittest004  splittest009  splittest014  splittest019  splittest024  splittest029  splittest034  splittest039  splittest044  splittest049  splittest054

$wc -l splittest015
10000 splittest015