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`!@`.`/6H?18.$ [email protected]```@?```,````5$5,[email protected],34N5%A480I[
. . . . . . (and so on)
By convention, uuencoded files are named with a .uue extension. To create a uuencoded file under Linux, enter a command like this:
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 by email.
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!
Comments - most recent first