LinuxCommandLibrary

uuencode

Encode binary file for transmission via email

TLDR

Encode a file and print the result to stdout

$ uuencode [path/to/input_file] [output_file_name_after_decoding]
copy

Encode a file and write the result to a file
$ uuencode -o [path/to/output_file] [path/to/input_file] [output_file_name_after_decoding]
copy

Encode a file using Base64 instead of the default uuencode encoding and write the result to a file
$ uuencode [[-m|--base64]] -o [path/to/output_file] [path/to/input_file] [output_file_name_after_decoding]
copy

SYNOPSIS

uuencode [OPTION]... [FILE] NAME

PARAMETERS

FILE
    Specifies the input binary file to be encoded. If this argument is omitted or specified as a hyphen (-), uuencode reads data from standard input.

NAME
    The name that the decoded file will take when processed by uudecode. This filename is included in the header of the encoded output, allowing the original file to be recreated with its intended name.

-m
    Enables base64 encoding instead of the traditional uuencode format. base64 is a more modern and widely adopted standard, especially for email attachments (MIME), producing a more compact and generally more compatible output.

DESCRIPTION

The uuencode command converts a binary file into an ASCII text format, making it suitable for transmission over communication channels that are designed primarily for text data, such as email or older newsgroup systems.

It achieves this by taking groups of 3 bytes from the input file and representing them as 4 printable ASCII characters, ensuring that all encoded data falls within the 7-bit ASCII range, thus avoiding corruption from systems that might strip high-bit characters or interpret control characters. The output includes a header line specifying file permissions and the original filename, and a footer line 'end'.

This mechanism was crucial in the early days of the internet for distributing software and other non-textual content reliably. Its counterpart, uudecode, is used to reverse this process and reconstruct the original binary file.

CAVEATS

While historically significant, uuencode is largely superseded by base64 and MIME for general-purpose binary file transfers, especially in modern email systems. The traditional uuencode format can sometimes face issues with line ending conversions or character set interpretations on some systems. Additionally, the encoded permissions in the header (e.g., 644) could potentially be a security concern if decoding untrusted files, as uudecode will attempt to apply them.

OUTPUT FORMAT

The output produced by uuencode is a block of human-readable ASCII text. It typically starts with a 'begin' line, which includes the file permissions and the filename (e.g., begin 644 my_file.jpg). This is followed by multiple lines of encoded data, where each line starts with a character indicating the number of encoded bytes on that line. The entire block concludes with an 'end' line on its own.

TRADITIONAL VS. BASE64 ENCODING

The traditional uuencode method converts every 3 bytes of input into 4 printable ASCII characters, plus an additional character per line to denote the length of the data on that line. In contrast, base64 encoding also converts 3 bytes into 4 characters but uses a different, more robust character set and does not include per-line length indicators; line wrapping is typically handled externally (e.g., at 76 characters) for email compatibility. The -m option allows uuencode to produce base64 output, bridging the gap to modern standards.

HISTORY

The uuencode utility originated in the early 1980s as part of Berkeley Unix (4.0BSD). It was developed to address the critical need for transmitting binary data over communication channels, such as early email networks and Usenet newsgroups, that were predominantly 7-bit ASCII text-based. Before the widespread adoption of MIME (Multi-purpose Internet Mail Extensions) and base64 encoding in the 1990s, uuencode was the de facto standard for exchanging executable programs, images, and other non-textual files reliably over the internet's nascent infrastructure. Although its direct use has declined, its principles laid the groundwork for subsequent binary-to-text encoding standards.

SEE ALSO

uudecode(1), base64(1), mail(1), shar(1)

Copied to clipboard