On Linux, files can be split into parts and recombined. This is often used to store large files across a series of disks.
- [Instructor] Files are really just a bunch of bits. So if we need to, we can slice and dice a file into various parts and put them back together again. Splitting a file might be necessary to store it on a few devices that might not be able to hold the full thing. Or to make individual smaller pieces available for download, or something like that. To split a file, we use the command split. Here in my Pictures folder, I have a picture of a cat. Let's split it into a few pieces and put it back together again.
He looks surprised, but it won't hurt. Here in the terminal, I'll use the command split and then specify -b. This tells split to divide the file by bytes. And I'll tell split to split this file into one megabyte chunks. Then I'll use -d, which appends decimal numbers, instead of strings to the end of each of the parts' file names. Then I'll provide the file to split, cat.jpg. And I'll provide a template for how to name the parts.
In this case, we'll call them cat.jpg.part. And then because of the -d option, the pieces of the file will be called part00, part01, and so on. Now I have four parts of the file and I can see that the first three are each one megabyte and then the remainder is in the last file. This file won't really be useful when it's split like this. Each piece is just a little bucket of bits that don't mean anything without the context of the other parts of the file.
If you're distributing the file or storing it or something like that, you may want to calculate the checksum of the original, and of each part, so you can compare later. Let's calculate the checksum of the original image with md5sum cat.jpg. Okay, we can put the parts back together again with a cat command, either explicitly, or by using Shell shortcuts or scripts. To do that, I'll write cat and then provide the file names of the pieces in the order that I want to put them back together.
Then I'll redirect the output of that to a new file. In this case, I'll call it cat2.jpg. Now let's compare the checksum of the original file with this file. I'll write echo, paste the hash, space cat2.jpg and pipe that to md5sum -c. It looks like everything's okay. I'll switch to my file browser and here's the cat2.jpg file we created.
I'll open it up. We know these pieces have been put back in the right order because we did it explicitly and the checksum matches and the picture looks correct. If we put the pieces back in an incorrect order, we'd have a bad checksum and the resulting data would be incorrect too. Split can create pieces of the file by line number, which can be useful for text, or by size, and there are various other options available as well. I encourage you to explore the man page for split to learn more.
Author
Updated
2/19/2019Released
10/3/2017Note: Because this is an ongoing series, viewers will not receive a certificate of completion.
Skill Level Intermediate
Duration
Views
Related Courses
-
Linux: Multitasking at the Command Line
with Scott Simpson39m 1s Intermediate -
Linux: Bash Shell and Scripts
with Kevin Dankwardt2h 46m Intermediate -
Linux: Files and Permissions
with Grant McWilliams1h 49m Intermediate
-
Introduction
-
Welcome1m 4s
-
-
Foundations
-
Foundations: What's Linux?5m 26s
-
Foundations: Distros10m 50s
-
Foundations: USB installer7m 46s
-
Linux on Azure7m 21s
-
Google Cloud Platform3m 37s
-
Linux on DigitalOcean6m 39s
-
-
System Basics
-
Logs5m 4s
-
Backing up data with rsync5m 35s
-
Filesystem Basics
-
Files on Linux4m 10s
-
File system basics: Archives6m 22s
-
Loop devices4m 35s
-
-
Working with Text
-
Working with text: Vim 1015m 15s
-
Working with text: nano 1015m 29s
-
Working with text: grep4m 23s
-
Working with text: sed7m 24s
-
Working with text: AWK2m 51s
-
-
Package Management
-
Package management: Basics6m 59s
-
-
Working Remotely
-
Remote files: curl and wget4m 42s
-
SSH: Secure access8m 8s
-
SSH: Tunnels3m 46s
-
X11 forwarding2m 52s
-
Using a SOCKS proxy4m 53s
-
Using a Squid proxy8m 43s
-
-
Process Management
-
Process management: ps4m 30s
-
Process management: top4m 53s
-
Process management: htop6m 11s
-
Customizing tmux3m 32s
-
-
Security
-
Firewall basics4m 5s
-
Understanding iptables6m 41s
-
File checksums3m 48s
-
Encrypting files New7m 14s
-
AppArmor4m 2s
-
-
System Administration
-
Logical volume management9m 59s
-
-
Exploration Topics
-
Windows Subsystem for Linux7m 20s
-
-
Troubleshooting Topics
-
Projects
-
Linux on an old PC6m 7s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Splitting and combining files