Thursday, June 30, 2011

split a large file into small files

If we want to split a large file into several smaller files, we can use split command (on linux).

split --bytes=SIZE largeFile smallFilePrefix

For example, i have a file a little larger than 50M(well, maybe that is not really large). If i want to split it into several small 1M files, i can do:

split --bytes=1M largeFile smallFile

And the you will find a lot of smallFile* files was generated. Let 's count them:

ls smallFile* | wc -l

I got probably 53 of them.

If we want to restore the original file, we can do

cat smallFile* > originalFile

No comments: