How to use the command uuencode (with examples)
UUencode is a command-line utility that encodes binary files into ASCII format, allowing them to be transported via mediums that only support simple ASCII encoding. This article provides examples of different use cases for the uuencode
command.
Use case 1: Encode a file and print the result to stdout
Code:
uuencode path/to/input_file output_file_name_after_decoding
Motivation: This use case is useful when you want to see the encoded content of a file directly in the terminal without writing it to a file.
Explanation:
path/to/input_file
: Specifies the path of the file that needs to be encoded.output_file_name_after_decoding
: Specifies the name of the output file after decoding. The decoded file will not be saved to disk, but this argument is still required.
Example output:
begin 644 output_file_name_after_decoding
M>7,!(;V9F,3,I;F)A9V5R#0H`
`
end
Use case 2: Encode a file and write the result to a file
Code:
uuencode -o path/to/output_file path/to/input_file output_file_name_after_decoding
Motivation: This use case is useful when you want to encode a file and save the encoded content to a specific output file. This allows for easy storage and transport of the encoded data.
Explanation:
-o path/to/output_file
: Specifies the path of the output file where the encoded content will be saved.path/to/input_file
: Specifies the path of the file that needs to be encoded.output_file_name_after_decoding
: Specifies the name of the output file after decoding. This argument is required.
Example output:
The file specified by path/to/output_file
will be created with the encoded content of the input file. The output file will be in the following format:
begin 644 output_file_name_after_decoding
M>7,!(;V9F,3,I;F)A9V5R#0H`
`
end
Use case 3: Encode a file using Base64 instead of the default uuencode encoding and write the result to a file
Code:
uuencode -m -o path/to/output_file path/to/input_file output_file_name_after_decoding
Motivation: This use case is useful when you want to encode a file using Base64 encoding rather than the default uuencode encoding. Base64 encoding is commonly used for email attachments and web-based data transfers.
Explanation:
-m
: Specifies the use of Base64 encoding instead of the default uuencode encoding.-o path/to/output_file
: Specifies the path of the output file where the encoded content will be saved.path/to/input_file
: Specifies the path of the file that needs to be encoded.output_file_name_after_decoding
: Specifies the name of the output file after decoding. This argument is required.
Example output:
The file specified by path/to/output_file
will be created with the Base64 encoded content of the input file. The output file will be in the following format:
begin-base64 644 output_file_name_after_decoding
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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