Monday, January 18, 2010

split and join files on MAC

on mac, there's split command - to split large files into smaller chunks. and why do i even want to split my files into smaller pieces you say? take my situation for example, i want to download a large file using a quite limited internet connection, so i split the file into smaller pieces to ease my download process. well you never know the reasons you might use this command but for me its quite handy :D

well for my situation, i'm downloading a 1.65 gb file and would like to split it into 10mb pieces. i open up a shell and just cd into the file's directory and
$ split -b10m filename
where split is the program, -b is to specify the size of the pieces (i'm using 10m to specify it to split into 10mb) and filename is the name of the filename that you want to split
after executing the commands, you will get lots of 10mb files with names starting with 'x' and followed by 'aa', 'ab', 'ac' and so on. it would look more like 'xaa' 'xab' 'xac' 'xad'. each file will have a maximum of 10mb size

so when i have finished downloading all the files, and i want to combine back all the pieces into its original file, i just simply use the cat command
$ cat x* > filename
after executing the command, i get my original file and a quick md5sum tells me that the file is not corrupted at all :)