Search code examples
linuxbashcommandoutputwritetofile

How to split and write the output of a linux command to multiple files of a specific size?


How can I split and write the output of my command in Linux bash, to multiple (text) 5M files (number of files does not matter)?


Solution

  • Pipe its output to split.

    Example:

    $ my-command-name-here | split -a 3 -b 5g - myFile.
    

    will produce files of 5GB having the names myFile.aaa, myFile.aab, myFile.aac a.s.o.

    Use -l instead of -b to produce files with the specified number of lines instead of bytes. Read man split or the online documentation.