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.

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

Print a row of characters across the terminal

Terminal - Print a row of characters across the terminal
jot -b '#' -s '' $COLUMNS
2010-04-13 22:03:39
User: dennisw
-1
Print a row of characters across the terminal

For BSD-based systems, including OS X, that don't have seq.

This version provides a default using tput in case $COLUMNS is not set:

jot -b '#' -s '' ${COLUMNS:-$(tput cols)}

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
printf "%`tput cols`s"|tr ' ' '#'
2010-04-05 17:12:35
User: kamathln
Functions: printf tr
Tags: tr tput printf
17

shorter than alternative

seq -s'#' 0 $(tput cols) | tr -d '[:digit:]'
2010-04-01 09:06:44
User: jgc
Functions: seq tput tr
Tags: seq tr tput
6

Print a row of characters across the terminal. Uses tput to establish the current terminal width, and generates a line of characters just long enough to cross it. In the example '#' is used.

It's possible to use a repeating sequence by dividing the columns by the number of characters in the sequence like this:

seq -s'~-' 0 $(( $(tput cols) /2 )) | tr -d '[:digit:]'

or

seq -s'-~?' 0 $(( $(tput cols) /3 )) | tr -d '[:digit:]'

You will lose chararacters at the end if the length isn't cleanly divisible.

printf -v row "%${COLUMNS}s"; echo ${row// /#}
2010-04-13 21:56:46
User: dennisw
Functions: echo printf
Tags: tr tput printf
4

Pure Bash

This will print a row of characters the width of the screen without using any external executables. In some cases, COLUMNS may not be set. Here is an alternative that uses tput to generate a default if that's the case. And it still avoids using tr.

printf -v row "%${COLUMNS:-$(tput cols)}s"; echo ${row// /#}

The only disadvantage to either one is that they create a variable.

echo -e ''$_{1..80}'\b+'
2015-05-05 22:13:33
User: knoppix5
Functions: echo
3

(here is character '+' repeated 80 times)

Sometimes needed to enhance the title of the script.

L(){ l=`builtin printf %${2:-$COLUMNS}s` && echo -e "${l// /${1:-=}}"; }
2

One of the first functions programmers learn is how to print a line. This is my 100% bash builtin function to do it, which makes it as optimal as a function can be. The COLUMNS environment variable is also set by bash (including bash resetting its value when you resize your term) so its very efficient. I like pretty-output in my shells and have experimented with several ways to output a line the width of the screen using a minimal amount of code. This is like version 9,000 lol.

This function is what I use, though when using colors or other terminal features I create separate functions that call this one, since this is the lowest level type of function. It might be better named printl(), but since I use it so much it's more optimal to have the name contain less chars (both for my programming and for the internal workings).

If you do use terminal escapes this will reset to default.

tput sgr0

For implementation ideas, check my

http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

Know a better way?

If you can do better, submit your command here.

What others think

scream, www.marcjacobs.us.com or www.coachoutletstore.net.co enjoy www.canada-goosesjackets.us.com the www.tommy-hilfiger-canada.ca cicadas www.louboutin.jp.net flap www.new-balance.ca its www.jimmy-chooshoes.com wings www.guccishoes.in.net when www.designerhandbagsoutlet.net.co you www.hollisteronlineshop.com.de bring www.oakley--sunglasses.com.au the www.newoutletonlinemall.com cool www.ugg-uggboots.net wind; www.rolex-watch.me.uk when www.pradaoutlet.com.co passing www.bottega-veneta.us.com Hasuike www.ralph-laurens.org.uk also puffed www.louis-vuitton-australia.com.au breath www.the-northface.net.co goods www.hollister-abercrombie.com.se products www.mk-outlet.us.com that www.mcmbags.net Lotus www.michael-kors-handbags.us.com aroma; www.giuseppezanotti.com.co hours www.rayban.org.es because www.swarovski-australia.com.au ignorance www.beatsbydre.com.co has www.toms-shoesoutlet.net been www.rayban-wayfarer.in.net poked www.retro-jordans.com hornet's www.hollisterclothingstore.org nest www.toms--outlet.com.co and www.wedding--dresses.ca stung airmax.misblackfriday.com his www.coachoutlet-online.com.co face www.bcbg-dresses.com was www.pandorajewellery.com.au bruised. www.newbalance.com.es Dig www.giuseppe-zanotti.net once, www.truereligion-outlet.com.co because www.bottegaveneta-bagsoutlet.com "small www.swarovskijewelry.com.co insects" www.tiffanyandco-canada.ca (Sparrow) www.adidas.org.es and www.hollister.us.org took www.hogan.com.de out www.chiflatiron.net.co a "snake" www.woolrich-clearance.com (Snake) www.nike-air-max.ca scared www.cheapoakley-sunglasses.in.net to www.adidasshoes.top fall www.michaelkorsoutletonline-sale.us.com from www.rolex-watches.us.com the www.mcmhandbags.com.co wall. Fortunately, www.coachoutletstore-online.com.co nothing www.nike-air-max.com.se serious. www.burberrys-outlet2016.com Leisure www.yoga-pants.net.co time, www.lululemon-australia.com.au will www.cheapmichaelkors.us.org collect www.eyeglassesonline.us.com some www.pulseras-pandora.com.es cigarette www.burberry-handbagsoutlet.com.co paper www.ralph-laurenoutlet.ca folded www.guccioutlet-sale.in.net triangle, www.designer-handbagsoutlet.us.com and www.cheaprayban.com.co partners www.longchamp-handbagsoutlet.us.com to www.nikefactory.org play; www.uggs.in.net (the www.michaelkorsoutlet.ar.com triangle on www.toms-shoes.net.co the www.ralph-lauren.com.au ground www.instylers.us.com and www.thejoreseproject.com put www.timberlandbootsoutlet.us.com his www.nike-rosherun.nl hand www.louis-vuitton-taschen.com.de on www.timberlandshoes.net.co the ground quick www.coach-factory.in.net photo www.pumaonline-shop.de shoot www.christianlouboutinshoesoutlet.org the www.michael-kors-canada-outlet.ca other www.rosheruns.us side www.babyliss-pro.us.com of www.nike-airmaxinc.co.uk the www.adidas-superstar.nl triangle www.nikefree-run.org.uk is www.prada-shoes.com.co the www.raybans.us.org triangle www.ralphs-lauren.co.uk that www.prada-handbags.com.co turned www.coachblackfriday.com their www.salvatoreferragamo.in.net a); www.moncler-outlet.us.org and www.tomsoutlet-online.com also www.maccosmetics.gr.com than www.p90xworkout.us.com own www.nike.org.es older www.polo-outlets.com.co brother www.edhardy.us.org and www.swarovski-online-shop.de sister www.michaelkors-uk.org.uk were www.cheap-raybans.com led to www.airmax-90.org a www.weddingdressesuk.org.uk wide www.longchamp.com.co flat www.barbour-jacketsoutlet.com on www.converse.com.de the www.asicsgels.de grass or www.ralphlaurenoutlet.us.com doing www.tiffany-jewelry.net "of www.oakley.com.de chicken" www.michael-kors.net.co or www.polos-ralphlauren.us.com "kill www.rayban-sunglasses.us.org the www.nikeskos.dk lamb" www.christian-louboutinshoes.com.co of www.hermesbags.jp.net the www.tommy-hilfiger.com.de game, www.the-northface.com.co before www.air-huarache.co.uk the www.lululemoncanada.ca election www.tommy-hilfiger.co.nl when www.ralphlaurenpolos.in.net one www.chanelhandbags.net.in eagle, nike.shoesoutlet.us.com then www.adidas.com.se tall www.canadagooses-2016.com in www.chanel-bags.com.co front www.toryburchoutlet-sale.us.com when www.ferragamo.com.co hens airhuarache.shoesoutlet.us.com , www.swarovski--uk.me.uk when www.nikemercurial.in.net the www.thenorthfacejackets.net.co rest www.rayban-sunglassesoutlet.co.uk of www.airhuarache.co.uk the www.michael-kors-outlet-online.us.org chicken, www.cheap-nike-shoes.net the www.uggs-onsale.net eagle www.coach-purseoutlet.net chasing www.ralphslauren-outlet.co.uk shot at www.tiffanyand-co.net.co the www.the-northfacejackets.us.com back www.oakleys-glasses.us.com of www.mcm-handbags.org the www.jordanrelease-dates.us.com chick, www.louisvuittons.com.co hen www.newbalance-outlet.org with www.pandora-charms.org.uk open www.michaelkors-outlet-online.com.co arms www.tiffany-und-co.de to www.swarovskicanada.ca protect www.coach-outletonline.net.co chickens, www.tory-burchshoesoutlet.net smart dodge www.oakley-sunglasses-canada.ca to www.longchamps.us.com keep www.ugg-bootsclearance.com eagle www.nike-schoenen.co.nl patting. www.ghd-hairstraightener.net Or www.coco-chanel.com.de a www.ralphlauren-polos.co.uk dozen www.cheap-michaelkors.com people www.airmax-2015.org sitting www.kate-spade.gb.net in www.abercrombie-and-fitch.us.com a circle, www.abercrombie-hollister.nl do www.nikefree-run.net a www.longchampoutlet.com.co do www.jordan-shoes.com.co Diushou Juan www.nikestore.com.de game: the www.hermesbirkin-bag.net hands www.louis-vuittonblackfriday.com of www.tommyhilfiger.net.co only www.coco-chanels.us.com one www.guccishoes.com.co person supra.shoesoutlet.us.com to www.replicarolex-watches.us.com take www.longchamp-bags.us.com the handkerchief www.thenorth-faces.co.uk out www.raybans-sunglassesoutlet.in.net of www.pradahandbags.net.co his mouth in www.burberryoutlet-sale.in.net a www.ugg-boots-australia.com.au circle www.nike-schuhe.com.de singing www.cheapshoes.com.co Diushou www.insanity-workout.us.com Juan www.tomsoutletonline.net songs, www.adidas-superstar.de danced www.rolexwatches-canada.ca around www.oakleyoutlet.ar.com the www.cheapuggboots.us.com circle www.christian--louboutin.in.net turning www.nike-air-max.com.de quietly www.abercrombie-kids.us.com throw www.cheapoakley-sunglasses.com the www.handbagsoutlet.net.co handkerchief www.ugg-boots.us.org in www.celine-bags.org the www.ugg-boots.ca back www.louis-vuittonoutletcanada.ca of www.replica-handbags.net.co a www.vans-schuhe.com.de person. www.truereligion-outlet.us.org Then www.newbalance-shoes.org run www.eyeglassframes.in.net around www.michaelkors.com.se in www.lauren-ralph.co.uk circles. www.burberryonlineshop.de If www.the-north-face.ca you www.michaelkorsbags.us.org have www.mcm-bags.in.net a www.montres-pascher.fr lap www.abercrombie-fitchs.us.com behind the www.harrods-london.co.uk handkerchief www.reebok.com.de patting, www.michael-kors.com.co this www.cheap-baseballbats.net people www.jordanretro.org have www.longchamphandbagsoutlet.net not www.christianlouboutinshoes.jp.net found www.iphone-cases.net.co the www.hermes-outlet.com.co person www.converse-shoesoutlet.com you www.ray-ban-outlet.us.com want www.rosherun.org.uk to www.gucci-taschen-outlet.de give a www.ugg-australia.com.de performance uggaustralia.misblackfriday.com for www.louisvuitton.so everyone; www.vans-shoes.co.uk a joke, www.nike-roshe-run.de sing www.michael-kors.com.es songs, www.rayban.co.nl or www.beats-by-dre.com.co back www.burberry2016.co.uk poem. www.burberrys-outlet.co.uk Then www.swarovski-crystal.us.com began www.nike-air-max.us Diushou www.scarpe-hoganoutlets.it Juan by airmax.shoesoutlet.us.com him www.soccer-shoes.us.com or her. www.omega-watches.us.com If www.poloralphlaurenoutlet.net.co this www.jimmy-choos.com is www.tiffany-andco.us.com discovered www.christianlouboutinoutlet.net.co immediately www.mkoutletonline.us.com took www.guccishoes-uk.co.uk the www.salomon-schuhe.com.de handkerchief www.toryburch-sandals.in.net catch www.oakley.org.es Diushou www.michael-kors-australia.com.au Juan www.burberryoutlet2016.us.com people, www.prada.com.de that www.airjordans.us Diushou www.thenorthface.com.de Juan www.cheap-oakleyglasses.us.com will www.louisvuitton-outlet.com.co continue www.burberryoutlet-canada.ca to www.timberlands-paschere.fr lose, www.oakley-outletstore.in.net someone www.pandorajewelry.top who www.nfl-jersey.us.com can www.bebeclothing.in.net back www.louis--vuitton.org.uk into www.tommy-hilfigeroutlet.com place; www.pandora.com.de catch, www.oakleyoutlet-online.us.com and www.thomas-sabos.org.uk throw www.polo-ralph-lauren.de this www.michael-korshandbags.org.uk man www.louisvuitton.jp.net who www.burberrybags-outlet.com has www.tnf-jackets.us.com sat www.mcmsworldwide.com on www.tommy-hilfiger-online-shop.de the www.chi-flatiron.us.com bit when this www.fashionclothes.us.com man www.marc-jacobs.us.com will www.tomsshoes-outlet.us.com be www.michaeljordan.com.de punished www.michael-kors-taschen.com.de performances. www.pumashoes.in.net We www.uggboots.com.de will www.uhren-shop.com.de play www.ralphlauren-polos.com.co along www.beatsbydrdre.co.com with www.cheap-jordans.net a www.michaelkors.so dozen www.tocoachoutlet.com "Stars www.beats-headphone.com.co over www.nikestore.us the www.outlet-burberry.net.co month www.nike-huarache.nl child" www.coach-factoryoutlet.net.co or www.basketballshoes.com.co "cat drilled www.ralphlaurenoutletonline.in.net 72 www.barbour-factory.com holes" www.air-max.com.de game. www.juicycouture.com.co (Read www.truereligionjeans.net.co the www.soft-ballbats.com article www.converse.net.co Network: www.polooutlets-store.com www.sanwen.net)Also www.mmoncler-outlet.com I www.hollister-clothing.in.net remember www.maccosmetics.net.co one www.hollisters-canada.ca summer, www.nike-maxfr.com that www.nike-shoes-canada.ca the www.northfaceoutlet.com.co acquisition www.nike--freerun.co.uk of www.levisjeans.com.co medicinal www.nikeshoesoutlet.org.uk city www.oakley-sunglasses.mex.com recovered www.nikefree5.net cicada www.juicycoutureoutlet.net.co skin www.supra-shoes.org (medical term www.guccihandbags.net.co called www.ralphlaurenoutletonline.us.org cicada), www.omegarelojes.es catty www.christianlouboutin.org.uk two www.adidas--canada.ca five. www.ray-bansunglasses.net So www.toms-outlets.us.com every www.coach-factoryyoutletonline.net day, www.nike-skor.com.se together www.montblanc--pens.in.net with www.toms-shoes.com.co my www.ralphlaurenepolo.com brothers www.nike-air-force.de holding www.cheapjerseys.us.org bamboo, www.soccer-shoesoutlet.com Dianzhe www.oakleysunglasses-cheap.in.net plastic www.zxcoachoutlet.com bags, www.christian-louboutin-shoes.ca and www.nike-roshe-run.com.es from www.rayban.com.de the village www.michaelkors.co.nl in www.uggboots.net.co the www.uggs.co.nl woods to www.kate-spade.in.net find www.gucci-outletstore.com a www.nike-tnrequinpascher.fr tree www.louisvuitton-outlets.us cicada www.calvin-kleins.us.com skin, www.michael-kors-outlet.us.org after www.ralphlaurenoutlet-online.us.com the www.cheapjerseys.com.co end www.uggsaustralia.com.co of www.michael--kors.us.com the www.new-balance-schuhe.de summer, we www.bcbg-max-azria.ca harvest relatively www.asics-outlet.us.com big, www.tiffany-andco.com.au full www.coachhandbags2016.us.com harvest www.longchamp.com.de four www.nike-shoesoutlet.us.com pounds, www.burberry-outlet.net.co to www.ralphlaurenonlineshop.de buy www.nikerosherun.us ten www.horloges-rolex.nl dollars. www.abercrombieand-fitch.ca The www.nikeair-max.es next www.burberry-outletstore.net summer we www.oakleys-sunglasses.us.com look www.ray--ban.ca for www.mizuno-running.net a www.michaelkorsoutlet-online.ar.com summer, www.uggsoutlet.com.co more www.burberry-outletonlinesale.in.net than www.ghdhair-straighteners.co.uk the www.ferragamoshoes.in.net first www.abercrombie-fitchsale.com year www.lululemonoutlet.gb.net looking www.replica-watches.com.co for www.tommyhilfigeroutlet.in.net even more, www.valentino-shoesoutlet.us.com I did www.katespadeoutlet.gb.net not www.burberry-handbags2016.in.net expect www.oakleysunglass-outlet.net there www.nikeair--max.fr to www.vans-shoes.net happily www.yoga-pants.ca after being www.adidas-schuhe-online.de told www.toryburchsale.com.co not www.nike-free-run.de recovered. www.gucci-shoes.net Cicada got www.converse-shoes.net hard www.ray-banocchiali.it skin, www.true-religion.com.co back www.nike-air-max.com.au at home www.thomas-sabo.com.de after shuffling, www.pandora-charms-canada.ca and www.rolexwatchesforsale.us.com

Comment by zyf543 3 weeks ago

Your point of view

You must be signed in to comment.