How to base64 encode /dev/random or /dev/urandom?


cat /dev/urandom is always a fun way to create scrolling characters on your display, but produces too many non-printable characters.

Is there an easy way to encode it on the command-line in such a way that all of its output are readable characters, base64 or uuencode for example.

Note that I prefer solutions that require no additional files to be created.

2/4/2014 12:07:05 PM

Accepted Answer

What about something like

cat /dev/urandom | base64

Which gives (lots of) stuff like


Or, without the (useless) cat+pipe :

base64 /dev/urandom

(Same kind of output ^^ )

EDIT : you can also user the --wrap option of base64, to avoid having "short lines" :

base64 --wrap=0 /dev/urandom

This will remove wrapping, and you'll get "full-screen" display ^^

8/8/2009 11:41:47 PM

A number of folks have suggested catting and piping through base64 or uuencode. One issue with this is that you can't control how much data to read (it will continue forever, or until you hit ctrl+c). Another possibility is to use the dd command, which will let you specify how much data to read before exiting. For example, to read 1kb:

dd if=/dev/urandom bs=1k count=1 2>/dev/null | base64

Another option is to pipe to the strings command which may give more variety in its output (non-printable characters are discarded, any runs of least 4 printable characters [by default] are displayed). The problem with strings is that it displays each "run" on its own line.

dd if=/dev/urandom bs=1k count=1 2>/dev/null | strings

(of course you can replace the entire command with

strings /dev/urandom

if you don't want it to ever stop).

If you want something really funky, try one of:

cat -v /dev/urandom
dd if=/dev/urandom bs=1k count=1 2>/dev/null | cat -v

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow