top 11 split command

Top 11 Split Commands To Break Large File Into Small Files

The split command is used to break the large files into a small file in Linux. Let’s see, top 11 split commands to break the large files. when you use the command it will use ‘x‘ as a prefix before a file which it has split.

Example 1: Suppose we have a file with tarball with a name “split.tar.gz” I will split all the files into small using the command.

split split.tar.gz

root@ubuntu:~# split split.tar.gz 
root@ubuntu:~# ls -l
total 24
drwxr-xr-x 2 root root 4096 Mar 22 14:30 split
-rw-r--r-- 1 root root 5716 Mar 22 14:31 split.tar.gz
-rw-r--r-- 1 root root 5716 Mar 22 14:31 xaa
-rw-r--r-- 1 root root 3750 Mar 22 14:23 xab

Check Out: How To Install Node.js And NPM On Ubuntu 19.04

Example 2: We can change the suffix length using “-a’” options.

split -a4 split.tar.gz

root@ubuntu:~# split -a4 split.tar.gz 
root@ubuntu:~# ls -l
total 200
-rw-r--r-- 1 root root 101867 Mar 22 14:39 split.tar.gz
-rw-r--r-- 1 root root 101867 Mar 22 14:39 xaaaa

Example 3: We can split the file with ‘–verbose‘ options.

split abcd —verbose 

root@ubuntu:~# split abcd --verbose
creating file 'xaa'
root@ubuntu:~# ls -l
total 108
-rw-r--r-- 1 root root 748 Mar 22 14:43 abcd
-rw-r--r-- 1 root root 748 Mar 22 14:43 xaa

Check Out: Troubleshoot Linux Server Performance Using vmstat Command

Example 4: We will split the file with a custom line number with ‘-l‘ options. I will split files with 10 lines per file.

split -l 10 abcd.txt –verbose

root@ubuntu:~# split -l 10 abcd.txt --verbose
creating file 'xaa'
creating file 'xab'
creating file 'xac'
creating file 'xad'
creating file 'xae'
root@ubuntu:~# ls -l
total 124
-rw-r--r-- 1 root root 1165 Mar 22 14:49 abcd.txt
-rw-r--r-- 1 root root 327 Mar 22 14:49 xaa
-rw-r--r-- 1 root root 300 Mar 22 14:49 xab
-rw-r--r-- 1 root root 251 Mar 22 14:49 xac
-rw-r--r-- 1 root root 284 Mar 22 14:49 xad
-rw-r--r-- 1 root root 3 Mar 22 14:49 xae

Example 5: We can split the file with size by using ‘-b’ options. I have created a 40mb file using fallocate command.

root@ubuntu:~# fallocate -l +40M test
root@ubuntu:~# split -b 20M test --verbose
creating file 'xaa'
creating file 'xab'
root@ubuntu:~# ls -lh | tail -n +2
-rw-r--r-- 1 root root 40M Mar 22 16:57 test
-rw-r--r-- 1 root root 20M Mar 22 16:57 xaa
-rw-r--r-- 1 root root 20M Mar 22 16:57 xab

Check Out: Enable and Disable Journaling On EXT4 File Systems In Linux

Example 6: We can split the file with the size and prefix given to the split files. The prefix is myfile instead of prefix ‘x‘.

root@ubuntu:~# split --bytes=20M test myfile
root@ubuntu:~# ls -l
total 81924
-rw-r--r-- 1 root root 20971520 Mar 22 17:07 myfileaa
-rw-r--r-- 1 root root 20971520 Mar 22 17:07 myfileab
-rw-r--r-- 1 root root 41943040 Mar 22 16:57 test

Example 7: We can split the file with a number like 00,01 etc instead of a name like aa, ab, etc with the ‘-d’ option.

root@ubuntu:~# split -d test --verbose
creating file 'x00'
root@ubuntu:~# ls -l
total 81924
-rw-r--r-- 1 root root 41943040 Mar 22 16:57 test
-rw-r--r-- 1 root root 41943040 Mar 22 17:12 x00

Check Out: How To Install Sentrifugo Open Source HR Management Tool On Linux

Example 8: We can generate n chunks of output files with ‘-n’ options.

root@ubuntu:~# split -n 2 test --verbose
creating file 'xaa'
creating file 'xab'
root@ubuntu:~# ls -l
total 81924
-rw-r--r-- 1 root root 41943040 Mar 22 16:57 test
-rw-r--r-- 1 root root 20971520 Mar 22 17:32 xaa
-rw-r--r-- 1 root root 20971520 Mar 22 17:32 xab

Example 9: We can avoid zero-sized chunks using ‘-e’ options.

root@ubuntu:~# split -n 2 -e test 
root@ubuntu:~# ls -l
total 81924
-rw-r--r-- 1 root root 1165 Mar 22 14:49 abcd.txt
-rw-r--r-- 1 root root 41943040 Mar 22 16:57 test
-rw-r--r-- 1 root root 20971520 Mar 22 17:36 xaa
-rw-r--r-- 1 root root 20971520 Mar 22 17:36 xab

Check Out: How To Block Ads In Google Chrome Using Group Policy

Example 10: We can split a big file and merge it into a single file.

I have a file created with 1.1G and I was not able to copy on the remote location as of its size. I will split the size and merge it into the single file on a remote location using cat command. 

root@ubuntu:~# du -sh file.iso 
1.1G file.iso

Split the file into 600M using the below commands. 

root@ubuntu:~# split -b 600M file.iso myfile
root@ubuntu:~# ls -l
total 2179084
-rw-r--r-- 1 root root 1165 Mar 22 14:49 abcd.txt
-rw-r--r-- 1 root root 1115684864 Mar 22 17:41 file.iso
-rw-r--r-- 1 root root 629145600 Mar 22 17:45 myfileaa
-rw-r--r-- 1 root root 486539264 Mar 22 17:45 myfileab

Now I will merge this split file into a single file.

root@ubuntu:~# cat myfilea* > file.iso
root@ubuntu:~# du -sh file.iso 
1.1G file.iso

Example 11: Verify the integrity of checksum. 

root@ubuntu:~# md5sum file.iso 
0318dc8fddd6d8ab48ff1d6dd56e14b3 file.iso

root@centos:~# md5sum file.iso 
0318dc8fddd6d8ab48ff1d6dd56e14b3 file.iso

You’re done split command in linux file top 11

Rate this article

Leave a Reply

avatar
  Subscribe  
Notify of