How To Split A Large File Into Multiple Smaller Files In Linux/Unix?

How To Split A Large File Into Multiple Smaller Files In Linux/Unix?


This post was last updated on August 1st, 2020 at 12:32 pm

Suppose you have an archive file of size more than 5GB, and if you want to burn it on a disc or transfer it to a filesystem with limited max filesize (say FAT32 with a limit of 4GB per file) then how will you do that. You have to split this file. Linux or Unix provides split command to break a file into multiple pieces. In this article, we will discuss split command with some examples.

Syntax of the split command

The syntax of the split command is given below –

split [options] filename prefix

Where replace the filename with the large file that you wish to split. Replace the prefix with the name you wish to give small output files.

In options, you could use –

-b, --bytes=NPut N byte per output file
-l, --lines= NPut N lines per record output files
-n, --number= NIt will generate N number of output files
--helpDisplay the help and exit
--versionThis will print the version split program and exit

There are a lot more options available you can check it in its manual page. Use the following command to open man page –

man split

How to split a large file into smaller ones?

To split a large file into smaller pieces you will have to use the following commands in your terminal-

Suppose we have named large_file with 3000 lines long. You can simply use –

split large_file

By default, split puts 1000 lines of input or whatever is left over for the last section, into each output file. This will output three 1000 line files xaa, xab and xac.

If you want to split the same file into 500 lines long parts then use-

split -l 500 large_file part

This will output six 500 lines long files with alphabets in the suffix: partaa, partab, partac, partad, partae and partaf.

Splitting a large archive file –

Recently I backed up my system, the archive backup.tar.gz created is of the size 21.3GB. Now to split it into files with the size less than 4GB(say 3900MB) use the following command –

split -d -b 3900m /backup.tar.gz backup

This will create backup00, backup01, backup02, backup03, backup04, and backup05. Here -d is used for digits in suffix instead of using alphabets and -b is used for bytes.

You can see the split files along with some other information such as size, date of creation, etc by running the following command –

ls -lh


Here we discussed to split a large file into multiple smaller pieces. You may also want to know how to reconstitute a file with cat command in Linux/Unix.

Previous How To Assemble Files With Cat Command In Linux/Unix?
Next How To Upgrade To Ubuntu 20.04 LTS From Ubuntu 18.04 Or Ubuntu 19.10?

About author

You might also like

Linux Topics 0 Comments

Concepts Of Standard I/O, Pipe And Filters In Linux/Unix

This post was last updated on August 3rd, 2020 at 02:48 pmContents1 Standard streams1.1 Input redirection – 1.2 Output redirection – 1.3 Append the output to an existing file-2 Pipe

How To 0 Comments

How To Extract A Zip File In Linux Using Terminal?

This post was last updated on August 1st, 2020 at 12:26 pmZip is an archive file format that supports lossless data compression. It is available for various platforms. Windows and

FreeBSD 0 Comments

How To Check System Hardware Information In FreeBSD?

This post was last updated on August 1st, 2020 at 10:25 amA computer system is consists of different types of hardware such as processor, RAM, hard disk, network cards, etc.


No Comments Yet!

You can be first to comment this post!

Leave a Reply