How to split and join files in Linux

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.

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.


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.

  1.   Rurick Maqueo Poisot said

    this also works for video files? I mean if I have a movie that is divided into 2 videos (one continuation of the other), can I put them together to have a single video with all the content?

    1.    tapestry said

      No, that's another topic !!!, you have to do it with a video editor. This is used to divide a video file into many parts, and then rejoin them, but for example, it will not be possible to play all the parts of the video separately, because they will not have a header, the entire video will only be played once it is join again. If you don't understand, ask again.

      1.    Rurick Maqueo Poisot said

        Oh! Thank you very much for the clarification

  2.   Old Linuxero said

    Be careful with the order of the cat!

  3.   diaztoledo said

    I think it doesn't work that well well, since depending on the video format you use, the file itself carries information on the duration of the video as well as other things, so if you use this method to join two videos, it is most likely that adds the content of the second file to the first one at the data level, but when you try to play the file, the two videos will not be played in a row, or it will give you an error in the file or only the first one will be played, as if you take a whole video and parts you cannot reproduce the two parts separately.

    Greetings.

  4.   James said

    How should I go about compressing all the files in a directory into individual files? for example, in folder1 there is file1 file2 and file3 and I want all but individually compressed file1.7zip file2.7zip file3.7zip

  5.   yoswaldo said

    It works for the images.iso?

  6.   yoswaldo said

    In this process there can be one bit corruption and damage the file?

  7.   Fred said

    When I try to split a file using split it tells me input / output error

    What can I do to solve it? 🙁