Skip to content

Something similar to /dev/zero

March 22, 2013

I have not write a new device. I have write a shell (dash compatible) function.

Usage is quite simple:

produce $((16 * 1024 * 1024)) urnd >/tmp/16mb-rnd

will create a 16 megabytes file filled with random data got from /dev/urandom


produce 1000000 125 >/tmp/1m-u

will create a 1 milion bytes file filled with character with octal code 125 (U).

Yes… you have to pass octal code… tr wants that!
Some useful hex to octal conversion:
0xff hex = 377 octal
0x55 hex = 125 octal
0xaa hex = 252 octal

Idea on tr '00' "\\${c}" has been taken from Something similar to /dev/zero? – look at Matir [02-08-2008, 11:36 AM] answer.

produce ()
	local s=${1:-0}
	local c=${2:-000}

	case ${c} in
			cat /dev/random | head -c ${s}
			cat /dev/urandom | head -c ${s}
			cat /dev/zero | head -c ${s}
			tr '\000' "\\${c}" </dev/zero | head -c ${s}

From → Technology

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: