What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Create a random file of a specific size

Terminal - Create a random file of a specific size
dd if=/dev/zero of=testfile.txt bs=1M count=10
2009-06-17 17:06:16
User: mstoecker
Functions: dd
Create a random file of a specific size

This will create a 10 MB file named testfile.txt. Change the count parameter to change the size of the file.

As one commenter pointed out, yes /dev/random can be used, but the content doesn't matter if you just need a file of a specific size for testing purposes, which is why I used /dev/zero. The file size is what matters, not the content. It's 10 MB either way. "Random" just referred to "any file - content not specific"


There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

This doesn't create a random file, it creates a zero'd file. What you mean is:

dd if=/dev/random of=testfile.txt bs=1M count=10
Comment by dfego 434 weeks and 6 days ago

I'm with dfego. With the modification, though, this is a great oneliner.

Comment by hooobs 434 weeks and 6 days ago

Might want to consider '/dev/urandom'.

Wikipedia says:

A counterpart to /dev/random is /dev/urandom ("unlocked" random source) which reuses the internal pool to produce more pseudo-random bits. This means that the call will not block, but the output may contain less entropy than the corresponding read from /dev/random. The intent is to serve as a cryptographically secure pseudorandom number generator. This may be used for less secure applications.

Comment by mungewell 434 weeks and 6 days ago

Mod'ed up as this is actually really usefull (with '/dev/zero') for creating a blank block onto which to re-image embedded files systems.

The problem is that all the old deleted files are really still there. If you 'dd' a blank page and then 'tar'/'untar' the filesystem onto it you can get your compression ratio back up.

Comment by mungewell 434 weeks and 6 days ago

@mungewell I had also considered using /dev/urandom as the input source as it will also work and I have used it before. Like I said, content doesn't really matter if all you need is the size, which is what I needed for download/upload speed testing, and how I came up with this.

@dfego I don't know if it works for you, but using /dev/random never tends to generate more than 1 kb of data in the file for me. As mungewell pointed out, I believe this is do to the fact that /dev/random does not reuse bits of noise from the entropy pool it uses to create the random data and thus the reason why I didn't use it in the initial code.

Comment by mstoecker 434 weeks and 6 days ago

"Random" means "random". Unfortunately, too many people have recently begun using it to mean things like "anonymous", "unknown", "miscellaneous", etc.

@mstoecker: Sometimes the content *does* matter.

Comment by dennisw 434 weeks ago

Create an alias for bash

function mkfile {

eval dd if=/dev/urandom of=$2 bs=1M count=$1



Comment by nublaii 363 weeks ago

Your point of view

You must be signed in to comment.