Dividing and joining files in Linux is a fairly simple task that will allow us to fragment a file into several smaller files, this helps us on many occasions to fragment files that take up a lot of memory space, either to transport it on external storage units or for security policies such as maintaining fragmented and distributed copies of our data. For this simple process we will use two important commands split and cat.
Table of Contents
What is split?
It's a command for systems Unix 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 original file name, being able to parameterize the size of the resulting files.
To delve into the scope and characteristics of this command we can execute man split where we can see its detailed documentation
What is cat?
For his part, linux cat command allows you to concatenate and display files, easily and efficiently, that is, with this command we can view various text files and we can also concatenate divided files.
In the same way as with split we can view the detailed documentation of cat with the command man cat.
How to split and join files 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 join files in Linux. For a general example where we want to divide a file called test.7z that weighs 500mb into several 100mb files, we simply have to 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 dividedaa, dividedab and so on. It is worth noting that if we add the parameter -d 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 rejoin the files that we have divided, we just have to execute the following command from the directory where the files are stored:
$ 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.