Linux: how to split a big compressed file into smaller files

Its very annoying when you try upload archive files into a server, many times there is an upload limit and then you need to split your…

Linux: how to split a big compressed file into smaller files
Photo by Glen Carrie on Unsplash

Linux: how to split a big file into smaller files (and join them again)

Its very annoying when you try upload archive files into a server, many times there is an upload limit and then you need to split your archive into smaller files.

To do this you can use the split command which comes with most Linux distros

Example:$ split -b 45M logs.tbz "logs.tbz.part"
$ ls -ltrh
total 311M
-rw-r--r-- 1 kpatronas kpatronas 158M Ιουλ  3 12:20 logs.tbz
-rw-rw-r-- 1 kpatronas kpatronas  45M Ιουλ  3 12:26 logs.tbz.partaa
-rw-rw-r-- 1 kpatronas kpatronas  45M Ιουλ  3 12:26 logs.tbz.partab
-rw-rw-r-- 1 kpatronas kpatronas  45M Ιουλ  3 12:26 logs.tbz.partac
-rw-rw-r-- 1 kpatronas kpatronas  23M Ιουλ  3 12:26 logs.tbz.partad

As you can see the maximum file size for each part is 45M and the original file still exists.

Parameters:

  • b: is used to specify the size of each part
  • “logs.tbz.part” is the prefix of each part file created after splitting.

To use the files we need to join them again to a single file, to do this:$ cat logs.tbz.parta* > ./big_logs.tbz