3 Unix / Linux uuencode Command Examples (Encode Binary File)

uuencode command is used to encode a binary file as explained in the examples below.

1. Basic uuencode Example

By default, uuencode takes input from the standard input, and writes it to the standard output as shown below.

# uuencode /dev/stdout
testing this is line 1
testing this is line 2
[press Ctrl-D here]

After typing the above two lines, press Ctrl-D, which will display the encoded output. Please note that just for explaining we are giving clear ASCII text in the above example.

# uuencode /dev/stdout
begin 644 /dev/stdout
testing line 1
testing line 2
[press Ctrl-D here]
>=&5S=&EN9R!L:6YE(#$*=&5S=&EN9R!L:6YE(#(*
`
end

2. Encode a Binary file to ASCII text

The following example encodes the test.tar.gz (tar compressed file) binary file, and displays the encoded ASCII data on the standard output.

# uuencode test.tar.gz /dev/stdout
begin 644 /dev/stdout
M'XL(`%[095$``^W/L0K"0!"$X:WS%/EJV0[LUVX>Z8RF/[%Y3\FR>/3S*Z&-8OW/(DG;:\^2ZM6E-
IR=9:W_[_J?]3KJS!%1I^O00`````````````````\(T[/@41D``H````
`
end

3. Encode a Binary file to ASCII text in BASE-64

By default uuencode command uses the standard UU encoding format. Use the option -m to encode in base-64 as shown below.

# uuencode -m test.tar.gz /dev/stdout
begin-base64 644 /dev/stdout
H4sIAF7QZVEAA+3PsQrCQBCE4a3zFPcEMnt78X0S7SIcJCf4+B52WigWQYT/
a4Zlmtl5Os+Xelq2Q7s124e6YymP7F5T8myePTzK6GNYv3PIknba8+S6tWlN
ydZa3/7/qf9TrqzBFRp+vQQAAAAAAAAAAAAAAAAA8I07PgURkAAoAAA=
====

Please note that to decode this ASCII text back to corresponding binary file, you need to use uudecode command.