Spurred on by a recent weekend full of hot-tub induced dehydration, beer, and lack of sleep, some friends of mine discovered an interesting (I think, I at least) capability of the command line computer interface. Prepare to be really geeked-out.
As I wrote briefly about last year, on the Linux command line, you can pass the output of one program into another by joining them together with | (the “pipe” character). For example, if you entered whois actsofvolition.com | gedit, it would take the output of the whois lookup for that domain name and open it in gedit, a text editor.
It occurred to one of us, in our sleep-deprived state, that you might be able to pipe the output of the random number generator into an audio player, and hear random noise. So, we tried this:
cat /dev/urandom | aplay
Let me explain: cat is a program to output the contents of a file. The /dev/urandom is a random number generator for linux. aplay is a simple sound player. So here, we are taking random data and asking an audio player to play it. It worked! It sounds like white noise. Here’s a short MP3 sample: random.mp3 (run out my headphone jack and and back into my line-in, since I could figure out how to record the audio directly to disk.
Hearing Your Hard-Drive
So, the next logical step (again, very little sleep) was to try sending in some non-random data. So we tried:
ls -R / | aplay
The ls command displays the contents of the current director. The extra options tell it to start at the root of your hard-drive (/) and go recursively into all sub-folders (-R). It basically lists out the file and folder names on your entire hard drive.
This sounded more like the bleeps and squawks of a modem making a dial-up connection (remember picking up another phone when someone was dialed-up to the internet?). Here's an MP3 sample: filesanddirs.mp3.
The Digital Anthem
Finally, we wanted to hear what some more structured data sounded like. Images and photos in compressed file formats like PNG and JPEG sound pretty much like random noise, due to the compression. However, un-compressed image files, like BMP (bitmap) files are very simple and structured.
cat usa.bmp | aplay
Here's the MP3 of the American flag bitmap file: usa.mp3.