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

How To Install Cockpit Web Console On CentOS 8?

The cockpit is a web console that makes it easy to administer the GNU/Linux server. It has a user-friendly web-based interface that enables you to carry out different system admin

How To 0 Comments

How To Hide Or Display Hidden Files/Directories In Linux?

This post was last updated on August 1st, 2020 at 01:56 pmLinux is a multiuser operating system that is getting popular day by day. Many new computer users start using

Linux Topics 0 Comments

How Vim Is Different From Vi?

Vi is a command-line text editor originally developed for Unix operating system. You can find it installed on almost any Unix-like operating systems including Linux, BSD, etc. Vi was originally


No Comments Yet!

You can be first to comment this post!

Leave a Reply