Operations 7 min read

Master Linux File Splitting and Merging with split & cat Commands

Learn how to efficiently split large files into smaller parts using the Linux split command and then recombine them with cat, covering syntax, practical examples, and helpful options for both operations.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux File Splitting and Merging with split & cat Commands

File Splitting – split

When network transfer limits require breaking a large file into smaller pieces, the Linux split command provides a convenient solution.

Command Syntax

-a   # specify suffix length (default 2: aa, ab...)
-d   # use numeric suffixes instead of alphabetic
-l   # split by number of lines (default 1000 lines)
-b   # binary split mode (supports units: k/m)
-C   # split by size while preserving line integrity

split [-a] [-d] [-l <lines>] [-b <bytes>] [-C <bytes>] [input_file] [output_prefix]

Usage Examples

# Split by lines
$ split -l 300000 users.sql /data/users_

# Use numeric suffixes
$ split -d -l 300000 users.sql /data/users_

# Split by byte size
$ split -d -b 100m users.sql /data/users_

Help Information

# Display help
$ split --help
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, default PREFIX is 'x'.

Options include:
  -a, --suffix-length=N   generate 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 records per output file
  -d, --numeric-suffixes  use numeric suffixes starting at 0
  -e, --elide-empty-files do not generate empty output files
  -l, --lines=NUMBER      put NUMBER lines per output file
  -n, --number=CHUNKS     generate CHUNKS output files
  -t, --separator=SEP     use SEP instead of newline as record separator
  -u, --unbuffered        copy input to output without buffering
  --verbose               print progress diagnostics
  --help                  display this help and exit
  --version               output version information and exit

The SIZE argument accepts integer units (K, M, G, etc.) and can be expressed in powers of 1024 or 1000.

For more details see the GNU coreutils online help or run <code>info '(coreutils) split invocation'</code>.

File Merging – cat

The Linux cat command easily concatenates multiple small files back into a single file.

Command Syntax

-n   # show line numbers
-e   # display $ at end of each line
-t   # show TAB characters as ^I
cat [-n] [-e] [-t] [file ...]

Usage Example

# Merge files
$ cat /data/users_* > users.sql

Help Information

# Display help
$ cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

Options include:
  -A, --show-all          equivalent to -vET
  -b, --number-nonblank   number nonempty output lines
  -e                      equivalent to -vE
  -E, --show-ends         display $ at end of each line
  -n, --number            number all output lines
  -s, --squeeze-blank    suppress repeated empty output lines
  -t, --show-tabs         display TAB characters as ^I
  -v, --show-nonprinting  use ^ and M- notation, except for LFD and TAB
  --help                  display this help and exit
  --version               output version information and exit

Examples:
  cat f - g   Output f's contents, then standard input, then g's contents.
  cat         Copy standard input to standard output.

For full documentation see the GNU coreutils online help or run <code>info '(coreutils) cat invocation'</code>.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxCATcommand-linefile managementsplit
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.