How to Split and Join Files using Command line from Terminal

In this Terminal Tuts session, you will learn how to split and join file using the command line in Linux

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:

  • Reduce processing time, as the smaller files are processed faster
  • Speed up data transfer through network file transfer, as smaller files are much faster than one large file.

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
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
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
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
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.

Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

24,261FansLike
192FollowersFollow

LATEST ARTICLES

cool and fun linux commands
The real purpose of this article is to help Linux newbies get comfortable and confident with the Linux command-line.  While knowledge and comfort of the Linux GUI allow great power, it is the mastery of the command line, or CLI, affords the Linux user unlimited power and certifies them as a Linux power user well on their way to becoming an expert.
best linux distros programmers
Linux distros have long been a favorite among programmers since the rise in popularity of the OS in the nineties. Programmers are technical by nature, and Linux distros appeal to that technical nature. Let's discuss why Linux is a great desktop OS for programmers and developers, and find out best distros suitable for them.
gamemode enable linux
GameMode is a combination of various libraries and daemons that allows all the users to improve the gaming performance on the Linux system. Developed by games publisher Feral Interactive, it improves gaming performance by requesting a group of options that will be applied temporarily to the Linux system.