Terminal Tuts

How to Split and Join Files using Command line from Terminal

How to Split and Join Files using Command line from Terminal

Sometimes you need to break large files into pieces for various reasons. Let's say you have a large video or an archive and you need to upload this file to your Dropbox account or Google drive or even to another PC. It becomes a daunting task, especially if the upload speeds are low.

Besides consuming time and resources, it's a bit risky in case the power goes off or if there was a disturbance in the network, rendering the broken upload useless. You have to restart all over again.

One of the best ideas to overcome this trouble is to split the large file into small segments and then upload or move them one at the time. When you want to open the file, you need to combine the file pieces and open the file.

Advantages of splitting large files into smaller ones:

In this tutorial, we are going to show you how to split large files into small pieces. And also how to combine those broken pieces into one file again.

Splitting Large Files Using Command Line

Now let's try to find a large file and break it into small pieces.

Step 1. To check file size in a human-readable format, you use the following command.

du -h MovieClip.mp4

On my PC I have found a file called MovieClip.mp4 with size around 2 GB as shown in the below screenshot:

MovieClip Size

As you can see this is a large file which will be hard to upload to your cloud, especially if you have a slow internet connection. So in the next step, we will show you how to split this file into smaller size files lets say 200 MB each, to make it easy while uploading.

Step 2. To split your file into smaller files with size 200 MB each and name the new data with MV, use the next command.

split -b 200M MovieClip.mp4 MV.

The previous command may take some time depending on your PC resources. So, when the command executes successfully move on to the next step.

Kindly note that you can try to execute the split command without specifying any extra arguments like next command.

split MovieClip.mp4 MV.

In this case and by default settings, the system will split the large file into small files starting with letter x and with each file containing 1000 lines.

Step 3. To check the output of the previous split command, use the ls command as follows.

ls -lh

MovieClip File and MV Files

As you can notice, you will find new files starting with MV and with size 200 MB each. Now it will be easy to upload or move or send them anywhere.

Combining Files using Command Line from Terminal

Step 1. Create a new directory to move smaller files to it.

mkdir ./NewMV/

Step 2. Move all the smaller size files starting with MV to the new directory.

mv MV* ./NewMV/

Step 3. Go to the new directory and list its content.

cd NewMV/

Create New Folder and Move Small Files To

Step 4. To combine small size files into a new file called CombinedMovieClip.mp4, use the next command.

cat MV.?? > CombinedMovieClip.mp4

Also, this command may take some time depending on your PC resources. After the cat command completes, you can list the directory content to check the newly created file.

Combine Files

You have successfully split your large file into small pieces and combined them again. If you need to know more about the split or cat commands you can easily refer to their manual pages using the following commands:

split manual page:

man split

cat manual page:

man cat

Finally, I hope you have enjoyed this tutorial, and for any further questions you can leave a comment, and we will be glad to help you.

Cursor jumps or moves randomly while typing in Windows 10
If you find that your mouse cursor jumps or moves on its own, automatically, randomly while typing in Windows laptop or computer, then some of these s...
How to reverse Mouse and Touchpads scrolling direction in Windows 10
Mouse and Touchpads not only make computing easy but more efficient and less time-consuming. We cannot imagine a life without these devices, but still...
How to change Mouse pointer and cursor size, color & scheme on Windows 10
The mouse pointer and cursor in Windows 10 are very important aspects of the operating system. This can be said for other operating systems as well, s...