Search and replace in multiple files and save them with the same names - quickly and effectively!

for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $files.new && mv $files.new $files; done;
Yeah, there are many ways to do that. Doing with sed by using a for loop is my favourite, because these are two basic things in all *nix environments. Sed by default does not allow to save the output in the same files so we'll use mv to do that in batch along with the sed.
Sample Output
No standard output on screen... just hit and boom. So, by the rule of the thumb first create a backup and then execute  or try to execute on some dummy files first.

-4
By: bassu
2009-05-07 20:13:07

What Others Think

why not use sed -i ? for files in $(ls -A directory_name); do sed -i 's/search/replaced/g' $files; done;
thebillywayne · 708 weeks and 6 days ago
Good catch thebillywayne. Thanks.
bassu · 708 weeks and 6 days ago
You can also trigger sed through 'find's exec function: find . -name "*.php" -exec sed -i 's/old/new/g' {} \;
birnam · 708 weeks and 6 days ago
there's a command called replace that does this: replace 'word' 'another word' -- * From the man page: NAME replace - a string-replacement utility SYNOPSIS replace arguments DESCRIPTION The replace utility program changes strings in place in files or on the standard input. Invoke replace in one of the following ways: replace from to [from to] ... -- file [file] ... replace from to [from to] ... < file
bunedoggle · 708 weeks and 5 days ago
the 'replace' program that bunedoggle mentioned is part of the mysql-server-5.0 package, at least on my debian/ubuntu system.
bwoodacre · 708 weeks and 3 days ago
"sed -i" isn't available on every UNIX system, as it's a GNU extension only.
realist · 694 weeks ago
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! Shareit Shareit apk Shareit pc
samprabhu · 132 weeks and 6 days ago
good catch by you thanks independence day mobile offers
Teligali0412 · 121 weeks and 1 day ago
sraboxing match-up. Do you like battling games? Do you appreciate participating in decisive duels against hazardous road contender If you do, attempt our this website
saraboxinggame · 114 weeks ago
sraboxing match-up. Do you like battling games? Do you appreciate participating in decisive duels against hazardous road contender If you do, attempt our this website
saraboxinggame · 114 weeks ago
https://getdailybuzz.com/download-shutterstock-images-without-watermark/ https://getdailybuzz.com/tekken-3-apk-download/ https://getdailybuzz.com/shareit-apk-download/ https://getdailybuzz.com/uc-browser-apk-download/ https://getdailybuzz.com/turbo-vpn-apk-download/ https://getdailybuzz.com/utorrent-apk-download/ https://getdailybuzz.com/download-utorrent-for-pc/ https://getdailybuzz.com/how-to-clear-cookies-on-android/ https://getdailybuzz.com/unzip-a-zip-file-in-android-phones-and-tablets/ https://getdailybuzz.com/how-to-transfer-files-from-computer-to-iphone-without-itunes/ https://getdailybuzz.com/full-form-of-nasa/ https://getdailybuzz.com/full-form-of-iso/ https://getdailybuzz.com/full-form-of-ngo/ https://getdailybuzz.com/full-form-of-eta/ https://getdailybuzz.com/full-form-of-unesco/ https://getdailybuzz.com/full-form-of-cv/ https://getdailybuzz.com/full-form-of-lmao/ https://getdailybuzz.com/full-form-of-rofl/ https://getdailybuzz.com/full-form-of-fmcg/ https://getdailybuzz.com/full-form-of-ctc/
getdailybuzz · 108 weeks and 2 days ago
You guys are amazing and thanks for sharing. Indeed you are right. Check out https://clashmod.net/clash-of-clans-mod-apk-download/
GodYato · 95 weeks ago
Download GTA 4 Apk Mobile is a really astounding game series with the reverberation of numerous elements, for example, novel ongoing interaction, drawing in storyline, and first rate designs. It's anything but too misrepresenting to say that GTA is the best round of the decade. Coming to GTA, you can encounter both great and dull stories covered up somewhere inside America.
DamianLAppling · 72 weeks and 6 days ago
Bakelite is the first plastic material in the world. Bakelite material in 1909, a Belgian scientific expert named Leo Baekeland made the principal altogether engineered plastic—and it would change the manner in which numerous customer merchandise were made. Baekeland called his plastic "Bakelite." (I surmise that sounded better than "Leolite.") Its properties made it's anything but a lot more extensive assortment of purposes than its archetypes. For instance, it was impervious to warm and would not direct power, so it's anything but a great cover—which made it especially helpful in the auto and electrical businesses arising in the mid 1900s.
rajandraparmar · 72 weeks and 5 days ago
Hello friends, in today’s article we will look at the"types of electrical wiring"and discuss in detail the different methods of wiring. What is Electrical Wiring? Definition: Electrical Wiring is nothing but the process of combining all the lights, fans, televisions, motors running in our house and arranging the wire properly, and bringing it to the distribution board is known as electrical wiring.
vishnu65 · 72 weeks and 5 days ago
Non Inverting Amplifier A non inverting amplifier never inverts the incoming input signal
suzen · 72 weeks and 2 days ago
Hydraulic Cement is a unique kind of cement that sets rapidly by synthetic response with water (hydration) and gets set with the drenching of water to the finely ground cement
Rukamnidevi · 71 weeks and 1 day ago
Knuckle Joint, otherwise called a mechanical joint, is an enunciation framed when two bars are consolidated with complete powers in which the projection of one finds a way into the other. A Knuckle Joint is made when there is a prerequisite for precise second or adaptability.
Rukamnidevi · 71 weeks and 1 day ago
hydraulic cement is a unique kind of cement that sets rapidly by synthetic response with water (hydration) and gets set with the drenching of water to the finely best cement
civiconcepts · 70 weeks and 4 days ago
seasoning of timber is a hydrothermal treatment of Timber, involving evaporation of moisture content in required proportion. compressive strength of concrete can be defined as the ability of material or structure to carry the loads on it without any crack or deflection. DPC means Damp Proof Course which is applied at basement levels, which restricts the movement of moisture through types of internal walls and floors of a building. Mostly courses are required in new build properties which are most sensitive to the Sand moisture content in order to prevent rising dampness subsequently.
civiconcepts · 70 weeks and 4 days ago
Types of Wood There are two main types of wood - hardwoods and softwoods. Hard woods come from broad leaved trees.
9to5civil · 62 weeks and 1 day ago
Thank You For Sharing.Read My New Article Cement Companies in UAE
prakash123 · 61 weeks and 1 day ago
How to get free iphone? Basically promotional companies that tend to gather the customer base of their customers. They offer worldwide trading of potentially different products, including the iPhone.
Davidjoyce · 61 weeks ago
Thank You For Sharing.Read My New Article building layout
pinokyo12 · 23 weeks and 4 days ago
Thanks for sharing this amazing info. Please check: https://apkvow.com/gbwhatsapp/com-gb-whatsapp/
amyjohnson4205 · 23 weeks and 3 days ago
Thanks for sharing valuable information. It's a very helpful article. M and PTracking
emmawastsan · 17 weeks and 4 days ago
Download WGT Golf Mod Apk (Unlimited Money, Unlimited Coins) 2022. 1.80.1. Sports. Play the #1 free golf game by Topgolf Media
shrutib · 15 weeks and 6 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale pug puppies indiana Amazing! This blog looks just like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!
rahimhh21 · 13 weeks and 2 days ago
Thank You For Sharing.Read My New Article burnished slate metal roof
9to5civil · 11 weeks and 6 days ago
Shareit is a cross-platform file sharing app that allows users to share files between devices without the need for a physical connection. The app uses a Wi-Fi or Bluetooth connection to transfer files, and is available for Android, iOS, Windows Phone, and Windows 10 devices. Shareit has been downloaded over one billion times and is one of the most popular file sharing apps available.
wangyou · 5 weeks and 5 days ago
Since 2008, Perfect House Pug Puppies has been the leading Pug puppy breeder in the US, providing premium Pug puppies for sale. Each puppy exhibits the professionalism and knowledge that have set Perfect House Pug puppies apart from other pug puppy breeders. The professionals at Perfect House Pug Puppies are dedicated about finding their puppies loving, beloved homes where they can enjoy long, healthy lives. A companion that has been produced for quality, health, and temperament that satisfies the breed standard is guaranteed by Perfect House Pug puppies, the pug breeder that has set the benchmark for exceptional customer satisfaction. If you are looking to buy a baby pug, Black and white pugs, Mini pug puppies for sale, Black and tan pug for sale, Teacup pug puppies for sale, Female pug puppies, pug puppies for sale, pug puppies for sale near me, pug puppies for sale under $500 near me. Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 5 weeks and 1 day ago
alasan suamiku mendua aliansi cinta bodyguard & majikan aldara all about monica alena all for carole alisha bukan cinta biasa all he'll ever be all for our little sister allura revenge journey all is found along with the gods all my romantic story with you alpha's bestfriend (farewell to sleep) all of us alpha aedon torn between love & duty allure alpha aiden's slave mate[id] almayra alpha sex slave [id] almighty me to reverse the bad ending although gloomy love alter amaizing ceo always fall for a villain amanda's future amazing grace vengeance amazing beasts ready go! ameera amazing doctor amonman broken dream amia's dream into the struggle an avery black mystery amidst the chaos an empress reborn an agent zero spy thriller an unlikely affair an island away from love[id] an unlucky girl an island away from love an urban warrior an unexpected love anak dari rahim pelacur an unlikely affair[id] anak penjahatku ana and dan vs the world anakku cerdas ana uhibbuka pria al kahfi andino + haven anak haram raja angel, say my name anak pancingan angel beside him anak untuk sang milyuner angel or devil anakku menjadi saksi mata perselingkuhan suamiku angels in the dust anda adalah valkyrja saya anna karenina andra & agatha annoying best friend angst in lightning marriage another life with adam ann veronica another shadow secret series anneila antara aku dan mantanmu annisa (kala takdir menuntunku padamu) antara aku kau dan 5 miliar annoying teacher antara cinta dan dendam. another liar anugerah yang terbuang another life – the scandal anumerta another sunshine apa bedanya antara aku, kamu dan tuhan kita apple of our eye antara benci dan cinta aranjo antara cinta dan gengsi sang mafia archigos antara kita dan wanita idamanmu arena two (book 2 of the survival trilogy) antinomi ares let there be carnage apakah akhirnya tuan xu tergoda arkana aplikasi menuju mati aroma obsesi apple of rich dads‘ eyes artrilogy pariban sang piso surit archigos generation as you wish, baby arena 1 slaverunners (book 1 of the survival trilogy) asa penggenggam takdir arena 3 (book 3 in the survival trilogy) ashes of midgard aresha
wangyou · 4 weeks and 6 days ago
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! https://www.shareitmod.com?ref=facebook&md=APSP
Cocominikki · 4 weeks and 1 day ago
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! https://www.shareitmod.com?ref=facebook&md=APSP
Cocominikki · 4 weeks and 1 day ago
Thank you for free file sharing app try it
Cocominikki · 4 weeks and 1 day ago
Manchester City will host Brentford at the Etihad Stadium in Week 16 of the 2022/2023 Premier League. This Premier League match ended bitterly for City. They lost to the guest with a score of 1-2. Ivan Toney put Brentford ahead in the 16th minute, then Phil Foden equalized for City in the 45+5 minutes. City were forced to bite their fingers after Ivan Toney scored the second goal for Brentford in this match in the 90+8 minute. City still has 32 points in second place. If standings leader Arsenal (34 points) later wins over host Wolverhampton, then the point difference between them will be five. This is the last Premier League match before the 2022 World Cup break. Clubs will compete again starting in December 2022. Manchester City Falls at Home Brentford surprisingly took the initiative to attack. After several times pounding City's back line in the early minutes, Brentford was even able to steal the first goal. Ivan Toney, who was recently left out of England's squad for the 2022 World Cup, fired Brentford ahead at the reigning champions with a header. City, of course, did not remain silent. However, City could only equalize at the end of the first half. Starting from Kevin De Bruyne's corner, which first hit Manuel Akanji's head, Foden equalized the score with his left foot. black panther wakanda forever streaming vf one piece red pelicula completa ".' Premier League Premier League After a draw in the first half, the match went tough in the second half. Citu dominated and created more chances, but their finishing was not optimal. Erling Haaland performed well below his best standards. Throughout the match, the Premier League's temporary top scorer was recorded as only releasing one shot, and that too was off target. City actually get disastrous in injury time. From Josh Dasilva's assist, Brentford scored the second goal as well as the decisive goal. That goal was scored by the same player who scored the opener, Ivan Toney. Ivan Toney's brace also made The Citizens fall at the Etihad Stadium. Starting XI and Match Statistics Manchester City (4-3-3): Ederson; John Stones, Manuel Akanji, Aymeric Laporte, Joao Cancelo; Kevin De Bruyne, Rodri, Ilkay Gundogan; Phil Foden, Erling Haaland, Bernardo Silva. Coach: Josep Guardiola. Brentford (3-5-2): David Raya; Zanka, Ben Mee, Ethan Pinnock; Mads Roerslev, Frank Onyeka, Vitaly Janelt, Mathias Jensen, Rico Henry; Bryan Mbeumo, Ivan Toney.
masdani233 · 3 weeks and 4 days ago
An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers. Business consultant Wollongong
sophiacharlie · 2 weeks and 3 days ago
Sanyo tv remote power button not working, which has its headquarters in Japan, is widely recognized for manufacturing excellent TVs on account that its inception in 1949. This is why it's so upsetting to be caught with a Sanyo TV Remote this is all at once now no longer operating, in order that your Sanyo TV is largely unusable. This is real whether or not you have a modern Sanyo TV Remote or an older model. Read directly to examine greater about why your.
Vsmith67 · 2 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands



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: