Split and join large files from terminal with slipt and cat

about split and join files with split and cat from terminal

In the next article we are going to take a look at how we can split and then rejoin large files from terminal. In many moments, users can find ourselves in need of split files oversized into smaller chunks, either to upload to Dropbox or send to another computer, if the available upload speed is not very high.

We can also find ourselves uploading a large file and either due to a power outage or a network problem, the load is interrupted. In this case, we will have to start the whole process all over again. For this and other reasons, a good way to move these types of files is divide the large file into small segments. In this way we can move them in a more agile way. When the receiver wants to open the file, he will only have to combine the small parts and so you can have a copy of the original file.

In the following lines we are going to see how to divide large files into small parts and how to combine these small parts back into a single file.

Split and join files from Ubuntu terminal

To perform this task, we are going to use two commands that can be found in our Ubuntu system, as are slipt and cat.

What is split?

This is a command for Unix systems that it will allow us to divide a file into smaller pieces. This will create the files with a name and an extension that will vary (aa, ab, and), and can also set the size of the resulting files.

In order to learn more about the characteristics of the split command, we will be able see your documentation typing in a terminal (Ctrl + Alt + T):

man split

man slipt

What is cat?

With the cat command we will be able to view different text files and we will also be able to concatenate split files.

As with the previous command, we will be able to consult the documentation opening a terminal (Ctrl + Alt + T) and typing in it:

you cat

man cat

Split large files from the terminal

To show as an example, I am going to use a ISO image of ubuntu-18.10-desktop-amd64.iso that I have on this team. Before we start let's check file size. For this task, in a terminal (Ctrl + Alt + T) we are going to use the following command:

du ISO file

du -h ubuntu-18.10-desktop-amd64.iso

As you can see, this is a large file that, depending on the available upload speed, can be difficult to share over the network. For this reason, the next step to follow will be to split this ISO file into smaller size files.

Split a file with split

To divide the ISO image of this example into files with a size, for example of 200 MB each one, we are going to open a terminal (Ctrl + Alt + T) and we will use the following command:

split -b 200M ubuntu-18.10-desktop-amd64.iso UB.

It has to be said that this command may take a while. The speed will depend on the size of the file that we want to divide and the resources of the PC in which we use it.

Once the division process is finished, we will be able check the output of the above command using the following command in the same terminal:

split ISO file

ls -lh

As you can see from the screenshot, we are going to find new files that start with UB. In addition, all of them will have a maximum size of 200 MB. Now it will be easy to upload, move or send them anywhere.

Merge files with cat

Once the file division phase is over, it is time to unite all the parts so that you can have a copy of the original file again. To develop this example, I will first create a new directory to move the small files.

mkdir ISO/

Next I am going to move all the smaller size files that start with UB to the new directory.

mv UB* ISO/

And I'm going to move to the new directory.

cd ISO/

At this point we will merge the UB named files into a new file called ISO-Ubuntu-merged.iso. To do this we will execute the following command:

Combining files in ISO

cat UB.?? > ISO-Ubuntu-combinada.iso

This command may take a while, depending on the resources of the PC where it is executed. After the cat command completes, we can take a look at the contents of the directory to verify the newly created file.

Confirmed the creation of the Ubuntu ISO image, we can now use it as best suits us.

merged iso image working in virtualbox

And so we can divide a large file into other small files and easily combine them again. You only need to use the commands sharpened y cat from the Ubuntu terminal.


Be the first to comment

Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.