This tutorial explains Linux “split” command, options and its usage with examples.
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]]
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:
$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
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.
- Apply for Programming Internship
- Check Information Technology Books
- Check Linux Books
- Practice Programming MCQs