split Command — Splitting Large Files in Linux¶
The
splitcommand divides a large file into smaller, more manageable pieces. It is commonly used when handling huge log files, database exports, backups, large CSV files, and files that need to be transferred over networks with size limitations.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
splitcommand - Split files by number of lines
- Split files by size
- Create custom file prefixes
- Create numeric suffixes
- Reassemble split files
- Process large production files
Prerequisites¶
Before starting this lesson, complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 Lessons 1–9
Why Learn split?¶
Imagine you have a:
- 20 GB log file
- 10 GB database export
- 5 GB CSV report
You cannot easily:
- Email it
- Upload it
- Analyze it
- Transfer it
Instead:
breaks the file into smaller pieces.
What is split?¶
The split command divides a large file into multiple smaller files.
Syntax:
Sample File¶
Create a sample file.
Display:
Output:
Split by Number of Lines¶
Split every five lines.
Files created:
View:
Output:
Custom Prefix¶
Instead of:
Use:
Files:
Numeric Suffixes¶
Instead of alphabetic suffixes.
Files:
Specify Suffix Length¶
Files:
Split by File Size¶
Split into 1 KB files.
Split into 10 MB files.
Split into 1 GB files.
Human-Readable Sizes¶
Supported units:
| Unit | Meaning |
|---|---|
| K | Kilobytes |
| M | Megabytes |
| G | Gigabytes |
Example:
Split by Number of Files¶
Suppose you want exactly four output files.
The file is divided into four approximately equal parts.
Display Created Files¶
Reassemble Files¶
Suppose:
Merge:
Verify:
No output means the files are identical.
Verify Integrity¶
Compare original and reconstructed files.
or
Matching checksums confirm the files are identical.
Common split Options¶
| Option | Description |
|---|---|
-l | Split by lines |
-b | Split by bytes/size |
-d | Numeric suffixes |
-a | Suffix length |
-n | Split into N files |
--verbose | Show created files |
Combining with Other Commands¶
Compress after splitting.
Split compressed logs.
Merge again.
Real Production Examples¶
Split a database export.
Split an application log.
Split a Kubernetes audit log.
Split a CSV report.
Production Perspective¶
The split command is commonly used for:
- Database backups
- Large log analysis
- Data migration
- Cloud uploads
- Secure file transfer
- Batch processing
Many enterprise environments split files before uploading them to cloud storage or transferring them across networks.
Hands-on Lab¶
Task 1¶
Create a sample file.
Task 2¶
Split into 20-line files.
Task 3¶
Use a custom prefix.
Task 4¶
Use numeric suffixes.
Task 5¶
Split by size.
Task 6¶
Merge files.
Task 7¶
Verify.
Task 8¶
Display generated files.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
split -l 1000 | Split by lines | CSV reports |
split -b 100M | Split by size | Log archives |
split -d | Numeric suffixes | Automation |
split -a 3 | Three-digit suffix | Large datasets |
split -n 5 | Equal parts | Parallel processing |
Production Troubleshooting Scenario¶
Scenario
A DevOps engineer needs to upload a 12 GB backup to cloud storage, but the storage service only accepts files up to 2 GB.
Tasks:
- Split the backup into 2 GB chunks.
- Verify the generated files.
- Reassemble the backup after download.
- Confirm that the reconstructed file matches the original.
Solutions:
Mini Challenge¶
Create:
Perform the following:
- Split into files containing 100 lines each.
- Create numeric suffixes.
- Use the prefix
records-. - Merge all files.
- Verify the merged file.
- Count the number of generated files.
Best Practices¶
- Use meaningful file prefixes.
- Verify reconstructed files using
sha256sumorcmp. - Split large backups before transferring them over the network.
- Prefer numeric suffixes (
-d) in automation scripts. - Remove temporary split files after successful verification.
Performance Tip¶
For very large files:
Choose a chunk size appropriate for your storage or network limitations.
When transferring files over unreliable networks, smaller chunks are often easier to retry than a single massive file.
Common Mistakes¶
❌ Forgetting to verify the reconstructed file.
✅ Always compare:
❌ Using alphabetic suffixes when scripts expect numeric ordering.
✅ Prefer:
❌ Choosing chunk sizes that exceed upload limits.
✅ Verify platform restrictions before splitting.
Interview Questions¶
Beginner¶
- What is the purpose of the
splitcommand? - How do you split a file every 100 lines?
- How do you split a file by size?
- What does
-ddo?
Intermediate¶
- Explain
split -n. - How do you reassemble split files?
- Why should you verify reconstructed files?
- What is the purpose of
-a?
Architect Level¶
- How would you split and transfer a 100 GB database backup?
- Why is
splituseful in cloud migrations? - How would you automate backup splitting, transfer, and verification in a shell script?
Summary¶
In this lesson, you learned:
- Splitting files by lines
- Splitting files by size
- Creating custom prefixes
- Using numeric suffixes
- Reassembling files
- Verifying file integrity
- Production backup workflows
The split command is an essential tool for handling large files in Linux. It simplifies storage, transfer, and processing while making large datasets easier to manage.
Key Takeaways¶
splitdivides large files into smaller parts.- Use
-lto split by lines. - Use
-bto split by size. - Use
-dfor numeric suffixes. - Reassemble files using
cat. - Always verify reconstructed files using
diff,cmp, orsha256sum.
What's Next?¶
fmt Command — Formatting Text in Linux
In the next lesson, you'll learn:
- Wrapping long lines
- Formatting paragraphs
- Adjusting line width
- Preparing reports and documentation
- Improving text readability