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

Rename all files which contain the sub-string 'foo', replacing it with 'bar'

Terminal - Rename all files which contain the sub-string 'foo', replacing it with 'bar'
for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done
2011-04-30 14:26:05
User: RanyAlbeg
Functions: mv
10
Rename all files which contain the sub-string 'foo', replacing it with 'bar'

That is an alternative to command 8368.

Command 8368 is EXTREMELY NOT clever.

1) Will break also for files with spaces AND new lines in them AND for an empty expansion of the glob '*'

2) For making such a simple task it uses two pipes, thus forking.

3) xargs(1) is dangerous (broken) when processing filenames that are not NUL-terminated.

4) ls shows you a representation of files. They are NOT file names (for simple names, they mostly happen to be equivalent). Do NOT try to parse it.

Why? see this :http://mywiki.wooledge.org/ParsingLs

Recursive version:

find . -depth -name "*foo*" -exec bash -c 'for f; do base=${f##*/}; mv -- "$f" "${f%/*}/${base//foo/bar}"; done' _ {} +

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives
rename 's/foo/bar/g' ./*
2011-05-01 15:55:20
Functions: rename
6

Would this command line achieve the desired function? My CLI knowledge is not great so this could certainly be wrong. It is merely a suggestion for more experienced uses to critique. Best wishes roly :-)

ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv
2011-04-30 00:21:10
User: windfold
Functions: ls sed xargs
4

Renames all files in a directory named foo to bar.

foobar1 gets renamed to barbar1

barfoo2 gets renamed to barbar2

fooobarfoo gets renamed to barobarfoo

NOTE: Will break for files with spaces AND new lines AND for an empty expansion of the glob '*'

ls | sed 'p;s/foo/bar/' | xargs -n2 mv
for f in *; do mv "$f" "${f/foo/bar}"; done
2011-04-30 09:53:20
User: uwe
Functions: mv
-2

without sed, but has no problems with files with spaces or other critical characters

rename foo bar directory/filename
2011-05-04 22:29:11
User: hexram
Functions: rename
-2

rename command in my system -Fuduntu running 2.6.38 Linux Kernel- is an ELF 64-bit LSB executable, not a Perl script. man page for rename command shows syntax as "rename from to where" (or something like that), so I am doing just what I have been told...

Know a better way?

If you can do better, submit your command here.

What others think

Just because a command has problems doesn't mean it's not clever.

Comment by eightmillion 292 weeks and 5 days ago

I can see what you mean, but I disagree.

Your clever is, by my terms, useless complexity.

In fact, a properly constructed command is less complex.

ls,sed and xargs does not indicate about anything but a waste of resources which is also dangerous.

Comment by RanyAlbeg 292 weeks and 5 days ago

Hey If you're going to hate why don't you put the hate where it belongs: In the comments of my command instead of marring the beauty of your command?

Comment by windfold 291 weeks and 6 days ago

Acutally, I take it back this command is better:

http://www.commandlinefu.com/commands/view/8370/bulk-rename-files-with-sed-one-liner

Comment by windfold 291 weeks and 6 days ago
rename

you want the version by Larry Wall, comes installed with Ubuntu.

Comment by unixmonkey365 273 weeks 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 6 weeks and 1 day ago

Your point of view

You must be signed in to comment.