Splitting and joining files in Macintosh and Linux

There are lots of tools available on PC (Windows) for splitting and joining files. There are very few available on Macintosh and Linux. But on Macintosh and Linux we don’t really need a separate tool for splitting and joining files the OS comes with one for us.

Splitting and joining files are pretty straight forward. There are two simple command line tools to do it. In this entire exercise we will be using only 3 command line tools.

1. Change Directory.

cd – change the current working directory to a specific Folder.
SYNOPSIS
cd [-L | -P] [directory]

2. Splitting the File.

split — split a file into pieces
SYNOPSIS
split [-a suffix_length] [-b byte_count[k|m]] [-l line_count]
[-p pattern] [file [name]]

3. Joining the File.

cat — concatenate and print files
SYNOPSIS
cat [-benstuv] [file …]

Lets get down to business and start splitting the file.

File Split
I didn’t have any big file to try the commands on. So I compressed Google Chrome application.

Created Google Chrome Zip File

Get into the folder containing the huge file using cd (change directory) command

cd path/to/the/folder/containing/file
split -b 50m “Google Chrome.app.zip” ChromePieces

“Google Chrome.app.zip” -> Name of the file to be split
ChromePieces -> Prefix of output file name.
-b -> Create smaller files byte_count bytes in length.
50 ->byte_count value.
m -> indicates megabyte pieces. k can be used instead for kilo-byte pieces

Used “split” command to split the file

The zip file size was 93.1 MB. So it ended up creating two files. As can be seen from the image above.

Joining Files

Used “cat” to join the files

cat ChromePieces* > Chrome.zip

We are joining all the files that have prefix file name “ChromePieces” and the resultant file will be created as Chrome.zip

A new (Chrome.zip) file is created.

Unzipped the newly created zip file.

You can unzip the Chrome.zip file and Google Chrome application extracted would work as normal. Split and cat can be used on most of the files. I have tried it on binaries(Application & Installers), Audio and Video Files, Text files.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s