Split file to pieces in Linux and join it again

By | January 10, 2025

More than 10 years ago I created binary editor for Windows called xedit. I mentioned this tool already twice here. To find these posts put in search text box xedit and click on Search button. This tool does a lot of useful things with files and I still utilize it sometime. It is still available to download from http://xedit.smike.ru/. Xedit permits to split file to pieces and gather it back again. Now I want to present how to split and combine file in Linux. Let us split executable shred which overwrites a file to hide its contents, and optionally deletes it. Before to do this I copy shred utility to tmp directory:

Step 1. Splitting to pieces with sizes of 10 Kbyte and add numerical extension to each piece:


split -b 10K -d shred shred.part

Step 2. Splitting result:


# ls -l shred*
-rwxr-xr-x. 1 root root 52928 Jan 10 15:49 shred
-rw-r–r–. 1 root root 10240 Jan 10 15:53 shred.part00
-rw-r–r–. 1 root root 10240 Jan 10 15:53 shred.part01
-rw-r–r–. 1 root root 10240 Jan 10 15:53 shred.part02
-rw-r–r–. 1 root root 10240 Jan 10 15:53 shred.part03
-rw-r–r–. 1 root root 10240 Jan 10 15:53 shred.part04
-rw-r–r–. 1 root root 1728 Jan 10 15:53 shred.part05

Step 3. Check that size of pieces is 10 Kbyte:


# echo $((10240/1024))
10

Step 4. Join file from pieces. New name of combined file is shred1:


cat shred.part0[0-5]>shred1

Step 5. Compare files shred and shred1:


# md5sum shred
90a1bfcac01b3ef8b5ad4192c75bc5a6 shred
# echo "90a1bfcac01b3ef8b5ad4192c75bc5a6 shred1" | md5sum -c
shred1: OK

Leave a Reply

Your email address will not be published. Required fields are marked *