Compress, Encrypt, Split and Transport Big Files Safely

by Ramesh Natarajan on April 6, 2009

Encrypt and Attach Big Files to Email AttachmentsEmail administrators may set a limit on the maximum attachment size that can be attached to an email. You can follow the steps mentioned below to transfer big files that cannot be attached to the email because of the attachment size restriction.

This technique can be used in general whenever you need to split huge files, encrypt and transfer it.

Following steps need to be followed on the sender side, for transporting the huge files safely and easily.

  1. Compress and optionally encrypt.
  2. Split & Send.

Following steps need to be followed on the receiver side:

  1. Receive & Join
  2. Uncompress

I. Steps Performed by the Sender

1. Compress the files and optionally encrypt it.

I prefer compression through zip, as it can be uncompressed in Windows also. If the receiver is
a windows user, he can unzip it without searching for a Linux server.

How to compress single file using zip ?

Syntax: $ zip input-file

How to compress multiple files using zip ?

Syntax: $ zip input-file1 input-file2 input-file3 ...

How to compress a directory using zip ?

Syntax: $ zip -r input-dir-name

How to encrypt the files while compressing ?

Syntax: $ zip -e intput-file

If the file contains sensitive information, you can encrypt the file while compressing it. Option -e encrypts the file with the given password, and the receiver should know this password for decrypting it. If the file size exceeds the specified limit after compressing also, then split the files as mentioned in the step 2.

2. Split the huge files

If the mail server’s maximum attachment size is 5 MB then split the files as mentioned below. This will split the huge file.txt into multiple 5MB files, which will be named as xaa, xab, xac and xad.

$ split --bytes=5M file.txt

$ ls -lh
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xaa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 xad

When you want to set custom name, then use the split command with PREFIX option as shown below. In the example below, the PREFIX is set to split_. So, the output files will be created as split_aa, split_ab, split_ac etc.,

Syntax: $ split --bytes=5M file PREFIX
$ split --bytes=5M file.txt split_

$ ls -lh
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_aa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 split_ad
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt

After the big file is split, you can attach these individual small files as email attachments. If you are a thunderbird user you can use Vim editor to compose email as we discussed earlier.

II. Steps Performed by the Receiver

1. Receive & Join the files

Once the receiver receives the email, joining these small files is very simple as shown below. ? is a shell meta character which matches any single character, so as we have xaa, xab, xac, and xad files get concatenated to the

$ cat xa? >


$ cat split_a? >

2. Uncompress the files

After joining these file you can uncompress it as shown below. It will uncompress and places the files in the current directory.

Syntax: $ unzip

If the file is compressed and encrypted, unzip will ask for the password to decrypt the file as shown below. After giving the right password it will decrypt and uncompresses the files in the current directory.

$ unzip
[] 01.txt password:

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 6 comments… read them below or add one }

1 Fran April 6, 2009 at 3:20 pm

Thank you for the tip.

2 VonSkippy April 8, 2009 at 5:10 pm

Sending large files via Email is HUGELY inefficient. Use a free service like FileFactory or YouSendIT (or course compression and encryption is a good idea).

3 Ramesh April 9, 2009 at 8:28 am


I agree that sending large files via Email is not efficient.. Sometimes for some unavoidable reasons (some stupid corporate policies? or, digitally sign a huge document and send it? ) you may have to transfer large files over email.

4 Marci April 29, 2009 at 3:54 am

Useful tips. Thanks.

5 tehno April 30, 2009 at 1:32 pm

why dont you mention ftp/scp/ puttySCP or WinSCP ? It is secure, easy and efficient…

6 Ramesh Natarajan April 30, 2009 at 6:07 pm

Thanks for the comments. We are glad that you found this tips useful.
In the list you’ve provided, except FTP, everything else is definitely a secure way to transfer big files. The focus of this article was primarily to show how to split big files, transfer the split files and combine the split files at the receiver end.

Leave a Comment

Previous post:

Next post: