Languages
[Edit]
EN

Bash - split file into parts (by size)

8 points
Created by:
Teilsa
1255

In this short article, we would like to show how to split file into parts in Bash.

Quick solution:

split -b 10MB big_file.ext part_file.ext.

Where:

  • -b 10MB means max size of single part,
  • big_file.ext means path to input file that we want to split,
  • part_file.ext. means prefix-path of output files
    (where command generates files as: part.ext.aa, part.ext.ab, part.ext.ac, ...).

 

Practical example

Let's suppose we have database backup as file that we want to split into multiple 10MB parts.

Example command:

split -b 10MB backup/batabase.sql backup/part.sql.

Example result:

File splitting into multiple parts in Bash.
File splitting into multiple parts in Bash.

 

Splitting input stream

Example command:

cat /path/to/somewhere.ext | split -b 10MB - /path/to/part.sql.

Where - means stdin usage with split command.

 

See also

  1. Bash - join multiple files

References

  1. split(1) - Linux manual page
  2. Standard streams - Wikipedia
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join