Skip to main content

Splitting a file into pieces of defined sizes in Linux

Posted in

Hi,

All of us have faced the problems of large file sizes when we want to backup our data on a DVD or some similar storage, or for example share music with a friend.

Yeah this doesn't apply to you if you have large size pen drive or external HDD, so people with the mentioned devices are asked to stop reading as it is not a use for you.

So you read this ? So you don't have that large devices blah blah blah...

What I wanted to split was my 8.5 GB of music for I need to format and install Fedora 11. I am using Fedora 10 now.

So instead of creating a compressed tar archive, I created a uncompressed tar archive just to hold the directories and files together in one file.

No compression, so archive creation is pretty fast (takes 20 minutes on my 4 Ghz machine).

Now I have an 8.5 GB tar archive called music.tar which I want to split so that I can fit in a standard DVD 4.7 GB.

The problem with the splitting tool bundled in Linux is that you cannot split the thing into decimal sizes. It creates unecessary problems.

I tried giving the size in Mega Bytes, but that doesn't work. So I decided to split it into 3 pieces 4 + 4 + the rest.

The rest would be close to .5 GB ~= 500 MB which can fit in a 1 GB pen drive (its damn cheap as compared to having a 8+ GB pen drive).

And the 4 GB parts will go each into 1 DVD.

So how to split the thing-

Linux provides a inbuilt utility from the package coreutils (its installed in all *nixes) so called split.

To split a file (music.tar) into 3 pieces I gave the command -

$ split --bytes='4G' -d --verbose music.tar music_split 

The --bytes='4G' tells split to divide music.tar into files of sizes 4*1024 MB.

-d option imples numeric suffixes

--verbose is self explanatory

then comes the filename and then the prefix of the destination files which i gave to music_split.

The command created 3 files namely music_split00, music_split01 and music_split02

Now the sizes of end files are such that they can be written into DVDs and USB sticks.

How to join these files after I have completed my reinstallation of my OS ?

That's very simple !

It uses the cat command.

To join these files and create music.tar back, I say -

$ cat music_split0{0,1,2} > music.tar

Which inputs to cat three file names - music_split00, music_split01, music_split02 which then joins them and echos to your shell. Its all binary data and of large size, so echoing to shell is wastage of resources and it may hang up your comp if you have a slow machine.

So you have the shell output redirection operator to a file called music.tar

And there ends the tutorial !

Post any comments you feel. If its boring say its boring ! At least I won't bore you in my future posts !

Trackback URL for this post:

http://www.itech7.com/trackback/348

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

geeky stuff! IT FLEW OVER MY

geeky stuff! IT FLEW OVER MY HEAD!

Really ? I don't think so. I

Really ? I don't think so. I have tried to be as simple as possible. Read carefully and try it out.

Nilesh Govindrajan

Site & Server Administrator
iTech7

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

Google Friend Connect (leave a quick comment)
Loading
  • No HTML tags allowed
  • You can enable syntax highlighting of source code with the following tags: [code], [apache], [bash], [c], [c++], [html4], [ini], [java], [javascript], [jquery], [php], [python], [ruby], [sql].
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • Images can be added to this post.
  • Use to create page breaks.
  • Textual smileys will be replaced with graphical ones.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

CAPTCHA
This is to verify that you are human visitor
Syndicate content