Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to encode an input string to base32 encoding directly from the shell. I'm looking to do this in ubuntu, but I imagine flavor doesn't particularly matter here.

Are there any existing linux/unix tools out there to simply do this?

Something along the lines of:

-bash-3.2$ echo -n 'hello' | base32
share|improve this question
up vote 9 down vote accepted

Hmm, a quick package search doesn't give anything like a single, standalone utility.

On the other hand, it shows that there's an appropriate Perl library, and it's easy enough to whip up a quick perl script. Something like:

$ sudo apt-get install libmime-base32-perl

And then a script like


use MIME::Base32 qw( RFC );

undef $/;  # in case stdin has newlines
$string = <STDIN>;

$encoded = MIME::Base32::encode($string);

print "$encoded\n";


$ echo -n "hello" | ./

The fairly sparse CPAN entry is:

So, a minor change will let you do decodes, also.

share|improve this answer
Thanks, MIME::Base32 seems to do the trick. – jdev May 4 '12 at 22:20

Just an improvement of cjc excellent answer so we can have a base32 utility which works similarly to base64 in the way we can encode and decode:

#! /usr/bin/perl

use MIME::Base32;
use strict;

undef $/;

my $string = <STDIN>;
my $changed;

if ( $ARGV[0] eq "-d" ){
        $changed = MIME::Base32::decode($string);
        $changed = MIME::Base32::encode($string); 

if ( $changed =~ /\n$/ ) {
    printf $changed;
    printf $changed . "\n";


$ base32 < <(echo -n 'abcdef')
$ base32 -d < <(echo  'MFRGGZDFMY')
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.