LINUX CLASSES - COMPRESSION, ENCODING AND ENCRYPTION
Do I Need a Magic Decoder Ring?
When you encode a file, you translate it into a format that other types of computers can understand. For example, if you want to send
an executable program, compressed files, word processor file, or any other binary data by email, you have to encode it in ASCII
(plain text) format first, or it will most likely be unreadable on the receiving end.
Most modern email programs can send and receive binary files, encoding them as MIME attachments and decoding them when
they're received. (Almost any Windows-based email program can handle attachments, as can Pine, Exmh, or Netscape Mail under
Linux.) But if you're partial to a low-tech mailer like the Unix mail command, or if you know that the intended recipient cannot
handle attachments, you'll have to uuencode your files before sending them or uudecode them after they arrive.
The uuencode and uudecode Commands
The uuencode program creates an encoded ASCII copy of a binary file, suitable for email transmission. The encoded file will
be 35 percent larger than the original and will look something like this (with the word begin, a number, and the original file name
on the first line, followed by a bunch of 61-character lines that all begin with "M"):
begin 644 panda.tar
M4$L#!`H`[email protected]`.`/6H?18.$ [email protected]```@?```,````5$5,[email protected],34N5%A480I[
M!P8;!KL,2P,)!PL).PD'%@.([email protected]!P8%[email protected]%PL*[email protected]@*.P4.%00.%P4*.`4.
. . . . . . (and so on)
By convention, uuencoded files are named with a .uue extension. To create a uuencoded file under Linux, enter a command like
uuencode panda.tar panda.tar > panda.uue
The first panda.tar on the preceding line is the name that appears on the "begin" line of the output file; the second
panda.tar is the name of the file you want to encode. (You might want to put a name other than the actual input file name on
the "begin" line if you're sending the encoded file to a DOS system where file names are more restricted.)
To decode a uuencoded file, enter a command like this:
The uudecode program will look for the "begin" line and create a decoded file with the name and file permissions specified there. In
the example here, the panda.tar file will be created in the current directory with permissions set to 644 (shorthand notation
for rw-r--r--, which equates to the following: owner: read/write; group: read; others: read).
Note: To calculate the numeric equivalent of a file permissions string, look at each triplet
in the permissions. Read gets 4 points, write gets 2, and execute gets 1. See
The Linux File System" for more on file permissions.
Files that are created with the tar, gzip, compress, or zip command in Linux must be uuencoded before they can be sent
Handling Encoded Files and Email
If you want to uuencode a file and email it in one step, try a command like this:
uuencode panda.tar | mail [email protected]
This tells uuencode to pipe the output directly to the mail program instead of creating a .uue file. If you want to take it one
step further, you could even archive, encode, and mail in one command, like this:
tar cvf - panda | uuencode | mail [email protected]
That should all make sense if you read about pipelines in "Living in a Shell" and understand that the dash in the tar
command means send the file to a pipeline instead of creating a tar file on disk. Of course you could also do this:
tar cvf panda.tar panda
uuencode panda.tar > panda.uue
mail [email protected] < panda.uue
But that's a lot more work!
Previous Lesson: Zip and Unzip
Next Lesson: Encryption
[ RETURN TO INDEX ]
Comments - most recent first
(Please feel free to answer questions posted by others!)
(31 Jul 2013, 16:54
Great information Bob!! Thanks!
Linux 2.6.32-358.14.1.el6.x86_64 #1 SMP Mon Jun 17 15:54:20 EDT 2013 x86_64
Just had uuencode installed and can't seem to get a file sent as an
attachment. I've tried several format versions but no luck, the data(file)
always comes through in the body of the email message.
Here's my latest try:
uuencode outfile.csv < infile.txt | mailx -s "Subject"
This format works on a Solaris server I have access to.
I'm not the Sys Admin.
Any help is greatly appreciated!
(20 May 2013, 18:50
I am trying to find a way to send multiple attachments using mailx.
I know you can do it by repeatedly using -a <file> or uuendcode and
then piping it. Is there better way as the number of attachment are subject
to change? Thanks for your help.
(26 Nov 2012, 11:30
I had done a script for backup. And attachement file to email i did, when
it run fails. Using UUENCODE COMMAND For what cases it's failing. Let me
(08 Oct 2011, 11:00
Excellent Tutorial Regards!!
(05 Oct 2010, 00:23
this is an excellent tutorial for absolute begginers
I welcome your comments. However... I am puzzled by many people
who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn
all you can, ask questions if you like. But don't ask me to send what you already have. :-)
NO SPAM! If you post garbage, it will be deleted, and you will be banned.