Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

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
1
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"

Alternatives

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 274 weeks and 2 days ago

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

Comment by hooobs 274 weeks and 2 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 274 weeks and 2 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 274 weeks and 2 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 274 weeks and 2 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 273 weeks and 3 days ago

Create an alias for bash

function mkfile {

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

}

mkfile

Comment by nublaii 202 weeks and 3 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts