Skip to content

Split command on Linux (split files)

The split command in Linux (split) is used to split large files into smaller n-files. The output files are generated according to the number of lines in the input file. The default is to split the file every 1000 lines. The names of the output files follow the standard file aa files ab file ac, and so on. You can specify a suffix for the output file.

The most common option is:

  • -n: Where n is the number of lines that will divide the input file;
  • -b bytes: Divide the file into a defined number of bytes.

In this example, the grocery list file is divided into 4 files with the suffix “list” with two lines each:

$ split -2 supermarket list <br></br>$ ls -l <br></br>-rw-rw-r-- 1 ec2-user ec2-user 14 Sep 13 09:08 listaaa <br></br>-rw-rw-r-- 1 ec2-user ec2-user ec2-user 13 Sep 13 09:08 listaab <br></br>-rw-rw-r-- 1 ec2-user ec2-user 14 Sep 13 09:08 listaac <br></br>-rw-rw-r -- 1 ec2-user ec2-user Sep 12 13 09:08 listaad

-rw-rw-r— 1 ec2-user ec2-user ec2-user 53 Sep 13 08:40 supermarket