Dividing and joining files in Linux is a fairly simple task that will allow us to fragment a file into several smaller files, this often helps us to fragment files that occupy a lot of memory space, either to transport it in external storage units or for security policies such as keeping fragmented and distributed copies of our data. For this simple process we will use two important split and cat commands.
What is split?
It is a command for Unix systems that allows us to divide a file into several smaller ones, it creates a series of files with the extension and a correlative of the name of the original file, being able to parameterize the size of the resulting files.
To delve into the scope and characteristics of this command we can run man split where we can see its detailed documentation
What is cat?
On the other hand, the cat of linux command allows to concatenate and show files, in an easy and efficient way, that is, with this command we can visualize various text files and we can also concatenate divided files.
In the same way that with split we can visualize the detailed documentation of cat with the command man cat.
How files are divided and joined in Linux using split and cat
Once you know the basics of the split and cat commands, it will be fairly easy to split and merge files into linux. For a general example where we want to divide a file called test.7z that weighs 500 mb in several 100mb files, we should simply execute the following command:
$ split -b 100m tes.7z dividido
This command will return 5 files of 100 mb resulting from the original file, which will have the name divided, divided, and so on. It is worth noting that if we add the -d parameter to the previous instruction, the name of the resulting files would be numeric, that is, divided01, divided02 ...
$ split -b -d 100m tes.7z dividido
Now, to unite again the files that we have divided, just execute from the directory where the files are stored the following command:
$ cat dividido* > testUnido.7z
With these small but simple steps we can divide and join files in Linux in a simple and easy way, I hope you like it and see you in a future article.