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.


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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Random Number Between 1 And X

Terminal - Random Number Between 1 And X
echo $[RANDOM%X+1]
2010-08-07 02:43:46
Functions: echo
27
Random Number Between 1 And X

If X is 5, it will about a number between 1 and 5 inclusive.

This works in bash and zsh.

If you want between 0 and 4, remove the +1.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
od -An -N1 -tu1 /dev/random
2013-09-10 08:57:16
User: sucotronic
Functions: od
6

It takes a byte from /dev/random whose source is the kernel entropy pool (better source than other solutions).

awk 'BEGIN { srand(); print rand() }'
2010-08-07 14:33:12
User: dennisw
Functions: awk
Tags: random number
-2

2d6 dice:

awk 'BEGIN { srand(); a=int(rand()*6)+1; b=int(rand()*6)+1; print a " + " b " = " a+b }'

3 + 6 = 9

echo "$(od -An -N4 -tu4 /dev/urandom) % 5 + 1" | bc
2010-08-10 12:10:21
User: dooblem
Functions: echo
-4

This is /bin/sh compatible.

Know a better way?

If you can do better, submit your command here.

What others think

The $[] form is deprecated. Use $(()) instead.

Comment by dennisw 330 weeks and 3 days ago

This is simple, but not sh compatible.

Just bash compatible.

Il prefer the awk version.

Comment by dooblem 330 weeks ago

num-utils has a 'random' function where you just have to do:

random 1..5
Comment by matthewbauer 330 weeks ago

The solution is wrong, or at least not well explained, because X have to be lower than 32767 (see man bash)

The awk version is ok, but you've to know that the seed generation is based in clock, so if you ask for numbers in a certain interval, you'll get the same numbers!!

num-utils package contains numrandom command, but it is not very efficient, because it generates a list of numbers and then picks one :P

Comment by sucotronic 169 weeks ago

how can i give x like an argument betweeen 100-100000

Comment by gerih26 151 weeks and 1 day ago

http://www.seattleseahawksjersey.us.com

http://www.uggcanada.com.co

http://www.uggbootscanada.ca

http://www.ugg-boots.fr

http://www.ugg-italia.it

http://www.michaelkorsoutlet-store.us.org

http://www.uggoutlet.eu.com

http://www.louis-vuittonoutlets.us.org

http://www.cheap-ugg-boots.com

http://www.true-religionoutlet.net.co

http://www.asicsshoes.name

http://www.christianlouboutinoutlet.com.co

http://www.cheaprolexwatches.name

http://www.louis-vuitton.name

http://www.montblanc-pens.name

http://www.outletmichaelkorsonline.us.com

http://www.michaelkors--outlet.us.org

http://www.designerhandbags.us.org

http://www.uggboots.gr.com

http://www.michaelkors--outlet.com

http://www.adidasshoes.net

http://www.uggssale.us.com

http://www.outlet-celine.com

http://www.polo-ralphlauren.cc

http://www.coach-factoryoutletsonline.us.com

http://www.uggbootsuk.in.net

http://www.louisvuittonofficial.us.com

http://www.raybansunglasses.uk

http://www.jordanretro.name

http://www.cheap--nfljerseys.us.com

http://www.hollisterclothing.net

http://www.louisvuittonhandbag.us.com

http://www.jordan4.net

http://www.uggbootsparis.fr

http://www.abercrombieandfitchoutlet.in.net

http://www.gucci-outlet.net.co

http://www.airmaxssale.com

http://www.montblancpen.us.com

http://www.uggmore.com

http://www.adidas-yeezy.us.com

http://www.timberlandboots.net.co

http://www.mbtshoes.us.com

http://www.cheapburberryoutlet.name

http://www.thenorthface.net.co

http://www.louboutinshoesoutlet.co.uk

http://www.cheapraybansunglasses.net.co

http://www.monclerjackets.com.co

http://www.burberryoutlet.in.net

http://www.moncleruk.in.net

http://www.raybanoutlet.net.co

http://www.ralphlaurenoutletuk.in.net

http://www.burberrysale.name

http://www.todsoutlet.in.net

http://www.ralphlaurenpolo.in.net

http://www.coachfactoryoutletclearances.us.com

http://www.uggsbootsstore.com

http://www.moncler--paris.fr

http://www.coachoutletstoreonlineclearances.us.com

http://www.pittsburghsteelersjerseys.us.com

http://www.uggbootscheap.com.co

http://www.uggsformen.in.net

http://www.ralph-lauren.me.uk

http://www.tomswedges.us

http://www.michaelkorsoutletforsale.com

http://www.supra-shoes.net

http://www.curry3.name

http://www.lebronjames-shoes.net

http://www.bostoncelticsjerseys.com

http://www.niketn-pascher.fr

http://uggs.uggaustralia.qc.com

http://www.coachfactoryoutletonlinesale.us.com

http://www.cheapjordansforsale.us

http://www.get-louisvuittonoutlet.com

http://www.nike-airmaxpascher.fr

http://www.rolexwatchesforsale.name

http://oakley.sunglassesonline.us.com

http://www.goldenstatewarriorsjerseys.us.com

http://www.redbottoms.org.uk

http://www.sunglassesoakley.com.co

http://www.uggs-pascher.fr

http://www.tomsshoes-outlet.com

http://www.uggsale.de.com

http://www.celine-outlet.us

http://www.truereligion-jeans.com.co

http://www.oakleysunglasses-outlet.com.co

http://www.lebronjames-shoes.name

http://www.coachclearance.us.com

http://www.michaelkorshandbagsonsale.com

http://www.gucci-outlet.name

http://www.montblanc.com.co

http://www.oakley-sunglasses.net.co

http://www.cincinnatibengalsjerseys.us.com

http://www.uggs.com.co

http://www.uggoutletforsale.in.net

http://www.ugguk.com.co

http://www.tiffanyandco.nom.co

http://www.fitflops.org

http://www.hogan-scarpe.it

http://www.uggsonsale.net.co

http://www.pandorajewelry.net.co

http://www.basketballshoes.name

http://www.canadagoose-pascher.fr

http://www.michaelkorsoutletoff.in.net

http://www.canadagoose.de.com

http://www.oakleysunglassescanada.ca

http://www.coachoutletstoreonlinesale.us.com

http://www.michaelkorsoutletstores.us.org

http://www.louisvuitton.me

http://www.adidastrainers.uk

http://www.instylercurlingiron.com

http://www.nhljerseys.org

http://www.ralphlauren-outlet.us.org

http://www.authenticlouisvuittonhandbags.us.com

http://www.rayban-sunglasses.com.co

http://www.pradaoutlet.net.co

http://www.minnesotavikingsjerseys.us.com

http://www.adidasnmd-shoes.us.com

http://www.insanityworkout.cc

http://www.michaelkorsuk.com.co

http://www.louisvuittonlvoutlet.us.com

http://www.uggcanada.in.net

http://www.uggoutlet.qc.com

http://www.tiffanyandcojewelry.com.co

http://www.adidasoutletshoes.com

http://www.uggboots4sale.com

http://www.oakleysunglassess.com.co

http://www.louisvuittonoutletdeals.us.com

http://www.tomssale.in.net

http://www.uggoutlet.gr.com

http://www.adidasyeezy350.us.com

http://www.uggslippers.de.com

http://www.fitflops.us.com

http://www.newyorkknicksjerseys.us.com

http://www.longchamp.us.com

http://www.gucci-outlet.org

http://www.clevelandcavaliersjerseys.us.com

http://www.nike-rosherun.in.net

http://www.true-religion.me.uk

http://www.uggsforwomen.in.net

http://www.replicawatches.name

http://www.tomsshoesuk.org.uk

http://www.washingtonwizardsjerseys.com

http://www.christianlouboutin.name

http://www.nikeoutletstores.us.com

http://www.louisvuitton.nom.co

http://www.louisvuittonhanbags.co.uk

http://www.katespadehandbagsoutlet.us.com

http://www.raybanpascher.fr

http://www.louisvuittonoutlet.de.com

http://www.michaelkorsoutletstoreonline.com

http://www.vansshoes.name

http://www.adidassuperstar.name

http://www.christianlouboutin-paris.fr

http://www.fitflopssaleclearance.us.org

http://www.louisvuittonoutlet.co

http://www.louisvuittonoutletsale.us.com

http://www.uggsuk.in.net

http://www.cheapjordansshoes.us.com

http://www.rosherun.org

http://www.newcanadagooseoutlet.com

http://www.newenglandpatriotsjerseys.us.com

http://www.oklahomacitythunderjerseys.us.com

http://www.louis-vuittonhandbags.com.co

http://www.canadagooseoutletsale.com.co

http://www.canadagoose.com.co

http://www.aididasyeezy.org.uk

http://www.coachoutletstoreonlineclearances.us.org

http://www.nike--rosherun.fr

http://timberlandboots.hugeoff.net

http://www.uggsoutlet.eu.com

http://www.juicy-couture.us

http://www.jordan13.org

http://www.ralphlaurenoutletonline.in.net

http://www.christianlouboutinoutlet.com

http://www.gucci.me.uk

http://www.raybansonsale.com.co

http://www.losangelesclippersjerseys.com

http://www.raybansunglasses.me.uk

http://www.louboutinfemme-pascher.fr

http://www.coachcanadaoutlet.com.co

http://www.uggoutlet.de.com

http://www.raybansunglassesoutlet.net.co

http://www.canada-gooseoutlet.name

http://www.rolexwatches.us.com

http://www.uggsoutlet.de.com

http://www.cheappandorajewelry.name

http://www.longchamp-sac.fr

http://www.officialcoachfactoryonlinesale.us.com

http://www.hermesbagusa.com

http://www.louboutinshoes.cc

http://www.pradahandbags.net

http://www.cheaprolexforsale.com

http://www.louisvuittonoutletstores.us

http://www.coachoutletsale.us.com

http://www.truereligionjeans-outlet.us.com

http://www.adidasoriginals.in.net

http://www.coach-bags.us.com

http://www.chicagobullsjerseys.com

http://www.monclerpascherhomme.fr

http://www.kevindurantshoes.name

http://www.louis-vuitton-borse.it

http://www.louisvuittonoutlet.net.co

http://www.louisvuittoncanada.com.co

http://www.michaelkors--outlet.com.co

http://www.burberry-outlet.com.co

http://www.mlbjerseys.org

http://www.uggsale.net.co

http://www.toms-shoes.cc

http://www.toms.us.org

http://www.uggbootssale.de.com

http://www.ralphlauren-outlet.net.co

http://www.louboutinshoessale.com

http://www.hollister-clothing.org

http://www.dallasmavericksjerseys.com

http://www.uggsforcheap.in.net

http://www.uggsaustralia.it

http://www.ralphlaurenclearance.in.net

http://www.louisvuitton-handbags.com.co

http://www.nfljerseyswholesales.us

http://www.uggsoutlet.gr.com

http://www.toryburch-outlet.in.net

http://www.jordan6.net

http://www.kobebryantshoes.name

http://www.tommyhilfigeroutlet.us.org

http://www.uggbootsuk.com.co

http://www.oakleys-sunglasses.us.org

http://www.nba-jerseys.us.com

http://www.cheapjordansshoes.in.net

http://www.adidas-nmd.co.uk

http://www.clarisonic.com.co

http://www.michaelkorsoutlet-onlinestore.us.com

http://www.cheapuggs.de.com

http://www.uggsonsale.de.com

http://www.north-faceoutlet.net.co

http://www.raybansunglassess.com.co

http://www.katespade.eu.com

http://www.louis-vuittonoutlet.com.co

http://www.sanantoniospursjerseys.us.com

http://www.gucci--outlet.com.co

http://www.miamiheatjerseys.us.com

http://www.coachfactoryoutlet-onlinestore.us.com

http://www.uggssale.com.co

http://www.true-religionjeans.in.net

http://www.adidasoutletstore.net

http://www.fitflopsuk.me.uk

http://www.coachfactory-outlet.in.net

http://www.uggslippers.com.co

http://www.themichaelkorsoutlet.com

http://www.cheapoakleysunglassess.com.co

http://www.officialmichaelkorsoutlet.us.com

http://www.katespadeoutlets.us.com

http://www.denverbroncosjerseys.us.com

http://www.retrojordans.name

http://www.jordanfemmepascher.fr

http://www.cheapraybans.us.org

http://www.coachoutletsaleonline.us.com

http://www.michaelkorsoutlet--online.com

http://www.michael-korsbags.us.com

http://www.jordan8.net

http://www.canadagooseoutlets.com.co

http://www.christianlouboutin-pas-cher.fr

http://www.outletsmichaelkors.us.com

http://www.canada-gooseoutlet.net.co

http://timberland.officialfree.net

http://www.uggssale.de.com

http://www.beatsbydrdresolo.us

http://www.cheapoakleysunglasses.net.co

http://www.ghdhairstraighteners.com.co

http://www.oakleyvaultoutlet.in.net

http://www.michaelkorsoutletcanada.com.co

http://www.cheap-jordans.us.com

http://www.kobeshoes.org

http://www.canadagooseuk.com.co

http://www.coachfactoryoutlet-online.eu.com

http://www.louis-vuittonoutlet.us.com

http://www.michael-korsoutlets.eu.com

http://www.canadagoosejackets.com.co

http://www.christianlouboutinsale.me.uk

http://www.louisvuitton-discount.com

http://www.outletmichaelkorshandbags.us.com

http://www.nikeoutletstore.us.com

http://www.christianlouboutinoff.us

http://www.ray-ban-sunglasses.com.co

http://www.rolexwatchesoutlet.us

http://www.pandorajewelry.name

http://www.nike-airmax.me.uk

http://www.jordanshoes.us.org

http://www.seattleseahawksjerseys.us.com

http://www.michaelkorsoutletclearance.us.org

http://www.louisvuittonparis.fr

http://www.uggbootsuk.eu.com

http://www.michaelkorsoutletonline.us.org

http://www.louisvuitton.de.com

http://www.jordan3.net

http://www.abercrombieoutletonline.cc

http://www.coachoutletonlinesale.com

http://www.edhardyclothing.in.net

http://ugg.uggsstore.eu

http://www.raybanssunglasses.com.co

http://www.truereligion-jeans.us

http://www.louisvuittonhandbags.net.co

http://www.airjordan-pascher.fr

http://www.jordansforsale.in.net

http://www.jordanconcords.net

http://www.oakleystore.com.co

http://www.canadagooseoutlet.eu.com

http://www.officialcoachfactoryoutlet.com.co

http://www.chanelbags.in.net

http://www.niketrainers.uk

http://www.louisvuitton-outlet.cc

201610.27wengdongdong

Comment by wengdongdong7 5 weeks and 5 days ago

Your point of view

You must be signed in to comment.