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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
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

Remove spaces from filenames - through a whole directory tree.

Terminal - Remove spaces from filenames - through a whole directory tree.
find . -depth -name '* *' -execdir bash \-c 'a="{}";mv -f "$a" ${a// /_}' \;
2012-02-28 04:03:40
User: DewiMorgan
Functions: bash find mv
1
Remove spaces from filenames - through a whole directory tree.

Sometimes, you don't want to just replace the spaces in the current folder, but through the whole folder tree - such as your whole music collection, perhaps. Or maybe you want to do some other renaming operation throughout a tree - this command's useful for that, too.

To rename stuff through a whole directory tree, you might expect this to work:

for a in `find . -name '* *'`;do mv -i "$a" ${a// /_};done

No such luck. The "for" command will split its parameters on spaces unless the spaces are escaped, so given a file "foo bar", the above would not try to move the file "foo bar" to "foo_bar" but rather the file "foo" to "foo", and the file "bar" to "bar". Instead, find's -execdir and -depth arguments need to be used, to set a variable to the filename, and rename files within the directory before we rename the directory.

It has to be -execdir and won't work with just -exec - that would try to rename "foo bar/baz quux" to "foo_bar/baz_quux" in one step, rather than going into "foo bar/", changing "baz quux" to "baz_quux", then stepping out and changing "foo bar/" into "foo_bar/".

To rename just files, or just directories, you can put "-type f" or "-type d" after the "-depth" param.

You could probably safely replace the "mv" part of the line with a "rename" command, like rename 'y/ /_/' *, but I haven't tried, since that's way less portable.

Alternatives

There are 3 alternatives - vote for the best!

Terminal - Alternatives
zmv -Q '(**/)* *(.)' '$f:gs/ /_'

Know a better way?

If you can do better, submit your command here.

What others think

I'm not sure why rename would be 'less portable', bash isn't found on all *nix's, its not even the default with some linux's (ubuntu for instance uses dash) ... but util-linux, which contains 'rename' would no doubt be installed. If you want 'portable' then it really should be POSIX. Anyhow, the above is really a simple task ... given the right shell (zsh):

zmv -Q '(**/)* *(.D)' '$f:gs/ /_'

Comment by khayyam 245 weeks and 4 days ago

20170802lck

http://www.mulberrysale.co.uk

http://www.coachoutletonline-clearance.us.com

http://www.polooutletstores.us.com

http://www.nikeairmax-90.co.uk

http://www.rayban--sunglasses.me.uk

http://www.adidasoutletstore.in.net

http://www.pumaoutletonline.com

http://www.airhuarache-nike.co.uk

http://www.oakleysunglasses-sale.us.com

http://www.louisvuittonhandbagsoutlet.us.com

http://www.burberryoutletstore.in.net

http://www.longchamp-handbags.org.uk

http://www.christianlouboutin-shoes.org.uk

http://www.louisvuittonoutletclearance.us.com

http://www.rolexwatchesforsale.me.uk

http://www.cheapfootballshirts.me.uk

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

http://www.pandorajewelryoutlet.us.com

http://www.ralphlaurenpoloshirts.org.uk

http://www.michaelkorsoutletkors.us.com

http://www.max1.nl

http://www.truereligion-jeans.org.uk

http://www.airmaxuk.org.uk

http://www.coachfactoryoutletsale.com.co

http://www.fitflopsshoes.co.uk

http://www.louisvuittonoutletlv.us.com

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

http://www.louis-vuittonhandbags.me.uk

http://www.coachoutletcoachoutletonline.us.com

http://www.swarovski-crystal.org.uk

http://www.asicsisrael.com

http://www.truereligionjeanssale.in.net

http://www.coachoutletclearancesale.us.com

http://www.pandoracharmsjewelry.me.uk

http://www.coachoutletclearance.us.com

http://www.canadagooseoutletstore.com.co

http://www.borselouisvuittonborse.it

http://www.nikeblazerpaschers.fr

http://www.canada-goosejackets.us.org

http://www.michael-korsoutletclearance.us.org

http://www.lebronjamesshoes.in.net

http://www.canadagoose-jackets.us.org

http://www.coachoutletonline.com.co

http://www.nikerosheone.us

http://www.louisvuittonoutletauthentic.us.com

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

http://www.mulberryhandbagsuk.org.uk

http://www.clevelandcavaliers.us.com

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

http://www.poloralphlaurenoutlet-online.us.com

http://www.shoelysale.com

http://www.guccioutletstores.us.com

http://www.montblancpenss.us.com

http://www.ralphlaurenpolo.us.com

http://www.coachoutlet-clearance.us.com

http://www.canadagooseoutletonline.com.co

http://www.ugg-bootsaustralia.us.com

http://www.louisvuittonoutletlouisvuittonoutletstore.us.com

http://www.ralphlaurenpoloofficial.us.com

http://www.newbalanceshoes.in.net

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

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

http://www.mbt-shoesoutlet.us.com

http://www.canadagooseoutletstore.us.org

http://www.uggoutletonline.eu.com

http://www.juicycoutureoutlet.net

http://www.sunglassescheap.org

http://www.poloralph-lauren.us.com

http://www.wholesale-nbajerseys.com

http://www.adidas-trainers.org.uk

http://www.mulberryhandbagssale.co.uk

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

http://www.ferragamooutletstore.net

http://www.uggboots-cheap.in.net

http://www.toryburch.com.co

http://www.nfljerseyswhole-sale.us.com

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

http://www.coachoutletstoreonlineclearance.us.com

http://www.salomonshoessalomonoutlet.us.com

http://www.oakleysunglassesformen.com.co

http://www.michaelkorsoutletonline-stores.us.com

http://www.truereligionjeans.org.uk

http://www.nikeairmax90.me.uk

http://www.replica-watchesforsale.us.com

http://www.mlb-jerseyswholesale.us.com

http://www.coachoutlet-onlines.us.com

http://www.fitflopssale.me.uk

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

http://www.2017wholesalenfljerseys.com

http://www.canadagooseoutletcanadagoosejackets.com

http://www.michaelkorshandbagsclearanceoutlet.us.com

http://www.mont-blancpens.com.co

http://www.ralphlauren-pascher.fr

http://www.hermesoutletstore.us.com

http://www.raybans-sunglasses.us.com

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

http://www.hollisterclothings.net

http://www.nhljerseyswholesales.us.com

http://www.coachhandbagsclearance.us.com

http://www.louisvuittonoutletstoreslv.us.com

http://www.ralphlauren-polo.org.uk

http://www.swarovski-crystal.me.uk

http://www.yeezyboost350sale.us.com

http://www.polo-outletstore.us.com

http://www.nikestore-uk.me.uk

http://www.michaelkorsoutletonlineofficial.us.com

http://www.katespade.org.uk

http://www.louis-vuittonhandbags.org.uk

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

http://www.christianlouboutinonline.us.com

http://www.yeezyboostoutlet.us.com

http://www.coachfactoryoutletstore.com.co

http://www.oakley-sunglasseswholesale.us.com

http://www.fitflopssale.us

http://www.marc-jacobs.us.org

http://www.michael-korsoutletuk.co.uk

http://www.christianlouboutinoutletsale.us.com

http://www.oakleysunglassesdiscount.com.co

http://www.raybansunglassesuk.com.co

http://www.longchampoutlet.us.com

http://www.ray-bansunglasses.com.co

http://www.christianlouboutin-outlet.me.uk

http://www.louisvuittonhandbagsoutlet.org.uk

http://www.edhardy.us.com

http://www.long-champoutlet.us.com

http://www.uggoutletsale.us.com

http://www.jordanshoes.us.com

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

http://www.louisvuittonoutletlouisvuittonhandbags.us.com

http://www.hermesbelts.us.com

http://www.cartier-watches.us

http://www.hollisterclothingstore.in.net

http://www.ferragamoshoesoutlet.net

http://www.louisvuittonoutlet-online.us.org

http://www.long-champoutlet.in.net

http://www.michaelkorshandbags.in.net

http://www.bottega-venetaoutlet.net

http://www.coachoutletonline-factory.us.com

http://www.michaelkorsoutlet-uk.me.uk

http://www.pandoracharmssaleclearance.org

http://www.rolexwatchesrolexoutlet.us.com

http://www.louisvuittonpascher.fr

http://www.fredperrypoloshirts.com

http://www.hollister-clothingstore.org

http://www.futbol-baratas.com

http://www.polo-lacostepascher.fr

http://www.sunglassesoakley.co.uk

http://www.longchampbags.co.uk

http://www.raybanscheap.us.com

http://www.pradashoesofficial.us

http://www.rolexwatchesforsale.in.net

http://www.hollister-clothingstore.in.net

http://www.michaelkorsoutletmichaelkorsoutletonline.us.com

http://www.michaelkorsfactory-outlets.us.com

http://www.nikerosherun.me.uk

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

http://www.air-huarache.org.uk

http://www.oakleysunglasseswholesalechina.us.com

http://www.oakleysunglassescheapoutlet.us.com

http://www.coachoutletcanada.com.co

http://www.borsegucci-outlet.it

http://www.cheapjordansfreeshipping.us.com

http://www.reeboktrainers.org.uk

http://www.linksoflondons.co.uk

http://www.oakleysunglassesoutletsale.us.com

http://www.michaelkorshandbags-outlets.us.com

http://www.louisvuitton-outletclearance.us.com

http://www.michaelkors-outletuk.org.uk

http://www.ralphlauren-outletuk.co.uk

http://www.christianlouboutinshoessale.us.com

http://www.nikeoutletstore.us

http://www.ysloutlet.us.com

http://www.pradaoutlet.us

http://www.louisvuitton-outletonlines.us.com

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

http://www.cartieroutlets.us.com

http://www.handbagslongchamp.us.com

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

http://www.niketrainersnikeshoes.co.uk

http://www.addidasshoes.net

http://www.giuseppe-zanotti-outlet.org

http://www.thomassabocharms.org.uk

http://www.fitflopssaleclearance.in.net

http://www.poloralph-lauren.org.uk

http://www.oakleysunglassescheapwholesale.us.com

http://www.hermes-birkin.in.net

http://www.airforce1.us.com

http://www.nike-store.org.uk

http://www.swarovskicrystaljewelry.us.com

http://www.raybansunglasses1.us.com

http://www.converseshoes.us.com

http://www.polooutletus.us.com

http://www.omegawatches.me.uk

http://www.cartieroutletstore.us.com

http://www.lacostepoloshirts.us

http://www.mbt5.com

http://www.nikeroshe-run.me.uk

http://www.uggboots-australia.in.net

http://www.nike-outletonline.com

http://www.nikeairmaxtrainers.co.uk

http://www.coachoutlethandbags.us.com

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

http://www.oakleysunglassesoakley.us.com

http://www.reebokoutletstores.us.com

http://www.pandorajewellery.cc

http://www.raybansunglassessale.com.co

http://www.toryburchoutletstores.us.org

http://www.jeanstruereligion.in.net

http://www.coachoutletstore.com.co

http://www.valentinooutlet.us.com

http://www.ralphlaurenoutletstores.us.com

http://www.katespadeoutletstore.us

http://www.burberry-outletstore.in.net

http://www.shoesjordan.net

http://www.michaelkorsbags.org.uk

http://www.outletchristianlouboutin.us.com

http://www.canadagoosejacketsuk.com.co

http://www.cheapmlbjerseys.net

http://www.coachfactoryoutletsales.us.com

http://www.michaelkors.eu.com

http://www.swarovskioutlet.us.com

http://www.herveleger.us.com

http://www.christian-louboutinoutlets.us.com

http://www.coachfactoryoutletcoachoutletonline.us.com

http://www.louisvuittonoutlet-onlines.us.com

http://www.nikeshoesforwomen.us.com

http://www.michaelkorsoutletclearance-online.us.com

http://www.ralphlaurenpolo-shirts.us.com

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

http://www.oakleysunglasseswholesaleauthentic.us.com

http://www.airjordan4.org

http://www.cartierwatchesforwomen.us.com

http://www.adidasukstore.org.uk

http://www.oakleysunglassesuk.com.co

http://www.ugg-outletstore.us.org

http://www.uggbootsclearance.us.org

http://www.fitflopssale.in.net

http://www.mulberry-handbags.co.uk

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

http://www.clearancefitflopssale.com

http://www.guccihandbags.us.org

http://www.maccosmetics.us.com

http://www.coachoutletonline.us.org

http://www.michaelkorshandbags-onsale.us.com

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

http://www.fitflopsoutletsale.com

http://www.fitflopsshoes.in.net

http://www.mizunorunningshoes.us

http://www.ralphlaurenukofficial.me.uk

http://www.guccioutletonlinestore.us.com

http://www.cheapoakleysunglassesformen.us.com

http://www.ugg-outletstore.in.net

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

http://www.nike-airmax2015.us

http://www.cheap-raybans.org

http://www.coachoutletoutlet.us.com

http://www.toryburchoutletofficial.us.com

http://www.nikeair-max.me.uk

http://www.canadagooseoutlet-stores.com

http://www.canada-gooseoutlet.us.org

http://www.cheapraybansunglasses-wholesale.us.com

http://www.mcmoutletstores.us.com

http://www.michaelkors.de.com

http://www.toryburchoutlets.us.org

http://www.michaelkors-handbags.co.uk

http://www.salvatore-ferragamo.in.net

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

http://www.michaelkors-outletonlineclearance.us.com

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

http://www.poloralphlaurenofficial.us.com

http://www.michaelkorsoutlett.us.com

http://www.chromeheartsoutletstore.us.com

http://www.ferragamo.eu.com

http://www.michaelkorsoutleta.us.com

http://www.canada-goosejacketsoutlet.us.com

http://www.pradasunglasses.us.com

http://www.adidasnmdshoes.us.org

http://www.katespadeoutletonlinestore.us.com

http://www.ferragamoshoes.org.uk

http://www.louisvuittonoutletlouisvuitton.us.com

http://www.christianlouboutinshoesoutlet.us.com

http://www.basketballshoes.us.com

http://www.adidas-wings.in.net

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

http://www.louisvuitton-outletofficial.us.com

http://www.suprashoes.us.com

http://www.coachfactoryoutlet-store.com.co

http://www.coachoutlet-onlines.eu.com

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

http://oakley.sunglassess.us.com

http://www.vans-shoes.cc

http://www.oakleysunglassesoutletcheap.us.com

http://www.airmax90.us.com

http://www.mulberrybagsuk.co.uk

http://www.michael-korsoutletclearance.com.co

http://www.michaelkorsoutletstoresofficial.us.com

http://www.pandoracharmsuk.com.co

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

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

http://www.cheapmichaelkors-handbags.us.com

http://www.kobeshoes.us

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

http://www.michaelkorswallets.us.org

http://www.guccioutletonlinestores.org

http://www.michaelkorsfactoryoutletonline.in.net

http://www.oakleysunglassesofficial.us.com

http://www.coachoutletonlinecoachoutlet.us.com

http://www.cheapreplicawatches.com.co

http://www.fitflop.in.net

http://www.raybansunglassescheap.com.co

http://www.toryburchoutlet-online.us.com

http://www.burberryoutlet.ca

http://www.pandorajewelrys.us.org

http://www.canadagooseoutletcanada.us.com

http://www.coachoutletonlinestore.eu.com

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

http://www.coachoutlet-onlineclearance.us.com

http://www.cartierwatchesforsale.us.com

http://www.oakleysunglasseswholesaleoakley.us.com

http://www.adidasnmduk.org.uk

http://www.michaelkors-outletonlinestore.us.com

http://www.soccer-shoes.us

http://www.louisvuittonoutlet1.us.com

http://www.foampositeshoe.net

http://www.raybansunglasses2.us.com

http://www.cheapsoccerjersey.net

http://www.pandorajewelrycharms.in.net

http://www.prada-handbags.co.uk

http://www.truereligion-jeanssale.us.com

http://www.authenticlouisvuittonoutlet.us.com

http://www.hollisterclothing-store.us.com

http://www.mulberryoutletstore.co.uk

http://www.truereligionjeansoutlet.co.uk

http://www.coachfactory-outletonline.com.co

http://www.michaelkorsofficial.us.com

http://www.nfljerseyswholesales.us.com

http://www.rolexwatchesoutlet.us.com

http://www.kevindurantshoes.net

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

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

http://www.nikeshoes.org.uk

http://www.louisvuittonoutletonlineofficial.us.com

http://www.niketrainers.me.uk

http://www.chromeheartsoutlet.com.co

http://www.nfl-jerseyswholesale.us.com

http://www.michaelkorsoutletoutlet.us.com

http://www.kobe9elite.us.com

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

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

http://www.oakleysunglassescheapsale.us.com

http://www.truereligionjeans-canada.com

http://www.truereligion-jeansoutlet.us.com

http://www.cheapraybansunglasseswholesale.us.com

http://www.coachoutletcoachfactoryoutlet.us.com

http://www.burberrysaleoutlet.us.com

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

http://www.canadagoosejackets-uk.com.co

http://www.cheapsnapbacks.net

http://www.canadagooseoutletstore.name

http://www.michaelkorsoutletcoupons.us.com

http://www.rolexreplicawatches.com.co

http://www.ralph-laurenpolo.us.com

http://www.lakersjerseys.us.com

http://www.cheapjerseyswholesale.org

http://www.birkenstocksandals.me.uk

http://www.eccoshoesoutlet.us.com

http://www.christianlouboutinoutletstore.us.com

http://www.rolex-watches.it

http://www.lebronjames.us.com

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

http://www.truereligion-jean.us.com

http://www.coachoutletclearanceonline.us.com

http://www.louisvuitton-outletonline.us.org

http://www.michaelkorshandbagsoutletfactory.us.com

http://www.mulberrybagsmulberryhandbags.co.uk

http://www.poloralphlaurensale.us.com

http://www.nikeoutlet-stores.us

http://www.instylerionicstyler.com

http://www.michaelkorsoutletfriday.us.com

http://www.truereligionjeanssale.com

http://www.sunglassesrayban.org.uk

http://www.michaelkorsuk-outlet.org.uk

http://www.ray-bansunglassesofficial.us.com

http://www.ugg-outletclearance.in.net

http://www.outletkatespade.us

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

http://www.cheapjordansonline.us.com

http://www.raybansunglassesoriginal.us.com

http://www.rolexwatches-uk.me.uk

http://www.nikefree5.us

http://www.nikeairmax90.nl

http://www.polotshirts.org

http://www.cheap-raybansunglasses.com.co

http://www.swarovskicrystals.com.co

http://www.rayban-sunglassesoutlet.us.com

http://www.longchamp-bags.me.uk

http://www.uggoutletclearance.us.com

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

http://www.louisvuittonoutletstoreofficial.us.com

http://www.coachoutletonlineclearance.us.com

http://www.coachoutletsales.us.com

http://www.uggbootsforwomen.us.com

http://www.skysneakers.com

http://www.wholesaleraybansunglasses.us.com

http://www.ferragamoshoes.com.co

http://www.nikeairmaxshoess.co.uk

http://www.kobebryantshoes.in.net

http://www.katespadehandbags.me.uk

http://www.todsoutlet.us.org

http://www.outletmichaelkors.co.uk

http://www.mulberry-handbagsoutlet.org.uk

http://www.coachfactoryoutlet.de.com

http://www.uggoutlet-clearance.in.net

http://www.truereligionoutlet-store.us.com

http://www.louisvuittonoutlet-official.us.com

http://www.canadagooseoutletonline.us.org

http://www.guccioutletonline.us.org

http://www.coachoutletonlinecoachfactoryoutlet.com

http://www.louisvuittonoutlet-lv.us.com

http://www.ralphlauren-polo.com.co

http://www.airmax90.org.uk

http://www.canada-gooseoutletstore.com.co

http://www.michae-kors-outlet.ca

http://www.cazal.us.com

http://www.outlettruereligion.in.net

http://www.truereligionjeansoutlets.us.com

http://mulberryoutlet.outlet-store.co.uk

http://www.ralphlaurenoutlet.org.uk

http://www.soccerjerseys.us.com

20170802lck

Comment by liuchunkai 19 weeks and 5 days ago

Your point of view

You must be signed in to comment.