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

Search and replace multiple files with substitution

Terminal - Search and replace multiple files with substitution
find . -name "*.txt" | xargs -n 1 perl -pi -w -e "s/text([0-9])/other\$1/g;"
2014-02-28 06:38:38
User: kennethjor
Functions: find perl xargs
0
Search and replace multiple files with substitution

Does a search and replace across multiple files with a subgroup replacement.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
2009-03-03 20:10:19
User: netfortius
Functions: grep sed
Tags: perl sed
25

recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found

also:

grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'
find . -type f -exec sed -i s/oldstring/newstring/g {} +
2009-12-09 00:46:13
User: SlimG
Functions: find sed
Tags: sed find
15

This command find all files in the current dir and subdirs, and replace all occurances of "oldstring" in every file with "newstring".

grep -rl oldstring . | parallel sed -i -e 's/oldstring/newstring/'
2010-01-28 08:44:16
Functions: grep sed
4

xargs deals badly with special characters (such as space, ' and "). To see the problem try this:

touch important_file

touch 'not important_file'

ls not* | xargs rm

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.

grep -rlZ oldstring . | xargs -0 sed -i -e 's/oldstring/newstring/'
2011-10-18 19:14:02
Functions: grep sed xargs
Tags: sed
1

Using -Z with grep and -0 with xargs handles file names with spaces and special characters.

replace old new -- `find -type f`
2012-12-13 20:22:17
User: brian
Tags: sed find
1

Search and replace recursively. :-) Shorter and simpler than the others. And allows more terms:

replace old new [old new ...] -- `find -type f`

Know a better way?

If you can do better, submit your command here.

What others think

Omega's Speedmaster had been one of the http://www.rolexreplicasonline.us/ rolex replica sale towards the online game, launched in the butt finish from the 50's. However the chronograph had been absolutely no brand new creation observed as soon as 1816 within http://www.rolexreplica.me.uk/ rolex replica uk astronomical wallet view, as well as within scaled-down watch type at the start from the twentieth hundred years, the actual http://www.watchesreplica2m.com/ rolex replica had been aged information. Actually, Rolex by itself have been producing chronograph http://www.rolexnicesale.co.uk/ rolex replica sale because the 1930s. Exactly what experienced transformed, although, had been period by itself publish battle, the actual 60s boomed along with prosperity as well as glamour, with this http://www.firstreplicarolex.co.uk/ rolex replica sale pace. Engine rushing, the activity associated with men, had been right now pleasant on the worldwide size, also it had been which excitement associated with pace which drawn a brand new variety of timekeepers the actual sports activities chronograph. Chronograph wrist watches up to after that actually http://www.replicawatch.us.com/ rolex replica sale personal had been designed along with set aside, delicate flavor, however which was absolutely no match for that roaring motors as well as sparkling fresh paint from the planet's quickest rushing devices.

Comment by hoowei 8 weeks and 5 days ago

Your point of view

You must be signed in to comment.