Linux Split and Rename Commands
Linux & DevOps February 5, 2018 1 min read 181 views

Linux Split and Rename Commands

How to split large CSV files and batch rename the resulting files in Linux.

Z

Zach Robichaud

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
Linux & DevOps 4 days ago 3 min read

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.

Comments (0)

Leave a Comment

No comments yet. Be the first to share your thoughts!