Main Menu

Search

LINUX: How To Split Large Files and Join them Back (Combining) in Linux? ("split" command)

In Linux there may be usecases where very large files have to be splitted and them joined back again. For e.g. usecases like uploading the large files to vendor Support cases, network limitations where copy of large files over a certain size will be restricted, sending the files in email etc. 

Before getting started with splitting and joining the files, always make a note of filesize and chksum of the file. Chksum of file can be gathered using below command.

md5sum <filename>

SPLITTING LARGE FILES

Below is command which can be used for splitting large files.

split -b <size_in_bytes> <filename> <suffix>

Below is explanation of arguments in above command.

<size_in_bytes> - size of each part file created after splitting.
<filename> - Filename to split.
<suffix> - Suffix name using which part filename has to created after splitting.

For e.g. if you want to split testfile.out which is 277K in size into parts of 27K size for each part, and the suffix name you want for the parts if testfile-part-, your command looks like following.


split -b 27k testfile.out testfile-part

Below are part files which are created after running above command.



-rw-r--r-- 1 root      root        6261 Aug 27 04:19 testfile-part-ak
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-aj
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ai
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ah
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ag
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-af
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ae
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ad
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ac
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-ab
-rw-r--r-- 1 root      root       27648 Aug 27 04:19 testfile-part-aa

JOINING / COMBINING PART FILES CREATED AFTER SPLITTING TO GET BACK THE ORIGINAL FILE.
Below cat command can be used to join all the part files.

cat <partfilename>*>filename

In above command replace the <partfilename>* with the starting name of part filenames followed by *, In the example shown here it will be testfile-part-*, filename will be the filename which you want to create after joining/combining all the split files. As an example below is how the command looks.

cat testfile-part-*>test1.out

Now if you check size and chksum of newly created file after combining the part files, size and checksum will be same as the original file which is split.

Products to which Article Applies


All UNIX environments

Additional References

https://www.ostechnix.com/split-combine-files-command-line-linux/




tarun boyella

No comments:

Post a Comment