Linux Split and Rename Commands
How to split large CSV files and batch rename the resulting files in Linux.
Zach Robichaud
Table of Contents
Splitting and Renaming Files in Linux
Need to break up a large CSV file—say, a million rows—into smaller files with 100,000 rows each? The split command makes this easy.
Splitting a Large File
split thefile.csv -d --lines=100000
The -d flag uses numeric suffixes instead of letters (e.g., x00, x01 instead of xaa, xab).
Restoring File Extensions
One quirk: split removes the file extension. You can restore it using the rename command:
rename 's/$/.csv/' x*
This appends .csv to all files starting with x.
Resources
How was this article?
Related Posts
Linux 'z' command is a must have terminal tool
The Linux z command completely changes how you move around the terminal. Instead of typing long paths or relying on tab completion, z learns the directories you visit and lets you jump to them using short, partial names. Once you use it, going back to plain cd feels painfully slow.
Testing Emails Safely
How to test email functionality without accidentally sending messages to real users.
htop: A Better Process Viewer
Why htop is a must-have tool for viewing system processes on Linux.
Comments (0)
No comments yet. Be the first to share your thoughts!