Useful if you’ve just received an email that says it has attachments but you can’t get them out (as I just did!). View the raw source of the email, copy the Base64 encoded text, drop in to a file, and run through this. The output will be the binary (or ascii) attachment.
perl -MMIME::Base64 -ne 'print decode_base64($_)' < file.txt > out
[](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)
[READER DISCOUNTSave $50 on terminal.training](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)
[I’ve published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)
[$49 - only from this link](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)
Published 14-Nov 2007 under #base64 & #bash & #binary & #decode & #code. [Edit this post](https://github.com/remy/remysharp.com/blob/main/public/blog/base64-decode-to-file.md)
Comments
Lock Thread
Login
Add Comment[M ↓ Markdown]()
[Upvotes]()[Newest]()[Oldest]()
?
Anonymous
0 points
10 years ago
If you are decoding bad email attachments use "base64 -di file.txt > out" instead, to ignore some garbage(eg. carriage return) on mail dumps.
?
Anonymous
0 points
10 years ago
i would recommend base64 -d also
?
Anonymous
0 points
12 years ago
I was looking for how to do this, and then, after I read your post, I realized I had already learned a simpler way.\
On Linux, the coreutils package comes with a program called simply "base64"\
To use it in the same way you described, just do this:\
base64 -d file.txt > out
\
A lot quicker to type, and easier to remember.
Just thought you’d like to know!
[Commento](https://commento.io)