5+ split Command Examples in Linux

«
»

This tutorial explains Linux “split” command, options and its usage with examples.

split- Split a file into pieces.

DESCRIPTION

Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, …; default size is 1000 lines, and default PREFIX is ‘x’. With no INPUT, or when INPUT is -, read standard input.

SYNOPSIS

split [-linecount | -l linecount ] [ -a suffixlength ] [file [name] ]

split -b n [k | m] [ -a suffixlength ] [ file [name]]

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

OPTIONS :

-a, –suffix-length=N
use suffixes of length N (default 2)
-b, –bytes=SIZE
put SIZE bytes per output file
-C, –line-bytes=SIZE
put at most SIZE bytes of lines per output file
-d, –numeric-suffixes
use numeric suffixes instead of alphabetic
-l, –lines=NUMBER
put NUMBER lines per output file

EXAMPLES

1. Split the file “newfile.txt” into three separate files called newaa, newab and newac each file the size of 22

$ split -b 22 newfile.txt new

2. Split the file “newfile.txt” into files beginning with the name “new” each containing 300 lines of text each

$ split -l 300 file.txt new

3. To split a file into more than 676 segments, enter:

advertisement
$split -l 5 -a 3 book sect

This example splits a book into 5-line segments named sectaaa, sectaab, sectaac, and so forth, up to sectzzz (a maximum of 17,576 files).

4. Split the file into 50 MB pieces with the given prefix

$ split --bytes=50M logdata mydatafile
$ ls -lh
total 204M
-rw------- 1 sathiya sathiya 102M Jul 25 18:47 logdata
-rw------- 1 sathiya sathiya  50M Jul 25 19:23 mydatafileaa
-rw------- 1 sathiya sathiya  50M Jul 25 19:23 mydatafileab
-rw------- 1 sathiya sathiya 1.6M Jul 25 19:23 mydatafileac

5. Split the file and name it with numbers

advertisement

Use -d option to name the files with number suffixes as 00, 01, 02 .. and so on, instead of aa, ab, ac.

$ split -d testfile
$ ls
testfile  x00  x01  x02

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.