O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Splitting files and data

Splitting of files into many smaller pieces becomes essential in certain situations. Earlier, when memory was limited with devices like floppy disks, it was crucial to split files into smaller file sizes to transfer data in many disks. However, nowadays we split files for other purposes, such as readability, for generating logs, and so on.

How to do it...

Generate a test file (data.file) of 100kb as follows:

$ dd if=/dev/zero bs=100k count=1 of=data.file

The above command creates a file filled with zeros with the size of 100kb.

You can split files into smaller files by specifying the split size as follows:

$ split -b 10k data.file
$ ls
data.file  xaa  xab  xac  xad  xae  xaf  xag  xah  xai  xaj

It will split data.file into many files, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required