Learn SPLIT Command with examples — LinuxTechLab

Shujat Husain
2 min readJan 8, 2020

--

Files can grow to a large size over time & these large files will not be easy to read or edit. Or if we need to move them to other systems, they won’t fit into the USB drive. For such scenarios, Linux presents us with a very useful command, SPLIT command.

As the name would suggest, the split command helps us to split the files into smaller files as per our requirements. We split the files by number lines, size, length etc. In this tutorial, we will discuss the use of split command with some examples.

Recommended Read: Linux commands you should never run on your system

SPLIT command

Split file based on number of lines

By default, the split command splits a file with 1000 lines in each split file. So if we have a file with 2300 lines, we will get three files with 1000, 1000 & 300 lines. The command for that is,

In the output, we will get files named ‘xaa’, ‘xab’ & ‘xac’ along with the original file.

Now if we need to change the default behavior i.e. change the number of lines per file, then we will use ‘l’ option,

This is will produce files with 500 lines each only.

Split files with a given prefix

To change the file names from ‘xaa’, ‘xab’ & so on to another prefix, we can use the following command,

# split files.txt new_prefix.txt

Now the files created would have the following names new_prefix.txtaa, new_prefix.txtab etc. We can also choose to add numbers to prefix rather alphabets, by using the option ‘d’,

# split -d files.txt. New_prefix.txt

Now output files would be named ‘new_prefix.txt01’, ‘new_prefix.txt02’.

Split files based on the file size

To split a large file into smaller files based on the size and not lines, we can use the following command,

So, here we are splitting the file to smaller files, all with size 100 Mb.

That’s it guys, we now end this tutorial on split command. Please do let us know if you have any questions, queries or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Donate us some of your hard-earned money:

Linux TechLab is thankful for your continued support.

Originally published at https://linuxtechlab.com on January 8, 2020.

--

--

Shujat Husain
Shujat Husain

Written by Shujat Husain

A TechEenthusiat who likes all new technologies & Gaming. Most of all love to write about Cloud & DevOPs & have my own blog as well (https://linuxtechlab.com).

No responses yet