Archive

Daily Archives: 2013-04-16

I recently posted a command to “Look Busy On *nix“:
$ cat /dev/urandom | hexdump -C | grep "34 32"

If you ran it, you console/terminal screen should have been filled with lines like these:

0013e1e0  8e 95 d7 0f de 2c 5d 88  d6 d7 34 32 f4 81 8f 37  |.....,]...42...7|
00146010  fc 70 e7 bd 18 5c 69 e4  2a 34 32 6a 0e 8a c0 46  |.p...\i.*42j...F|
00147fb0  34 32 43 24 ba b5 42 1a  94 18 d0 7b c9 cf c1 01  |42C$..B....{....|
0014efe0  c1 54 34 32 ab 32 36 f7  dd 7d 34 d5 74 a2 b3 58  |.T42.26..}4.t..X|
0014f400  c6 34 32 d8 81 57 b9 68  8f 31 5b 00 45 37 e1 4c  |.42..W.h.1[.E7.L|

I will break apart the command and explain what it actually did.

$
Indicates that this command should be run as a regular user (i.e. without root privileges). This isn’t actually part of the command and shouldn’t be included when typing it into the shell.
cat

Output the contents of the specified file(s) to stdout.
/dev/urandom
The file from which to read. /dev/urandom is a special file that acts as a pseudo-random number generator.
|
Redirects or “pipes” the output of the previous command into the input of the next command (stdout to stdin).
hexdump
Outputs a hexdump of the specified file, or stdin if no file specified.
-C
From the man page:
Canonical hex+ASCII display Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in %_p format enclosed in “|” characters.
grep
Outputs the lines that contain the given pattern in stdin or the specified files.
"34 32"
The pattern to match. Incidentally, this specific pattern is the hex code of the character sequence 42.

You could have done this without grep. The only reason why grep is included is because the output would be too fast otherwise. Try it.