Gentoo Archives: gentoo-user

From: Etaoin Shrdlu <shrdlu@×××××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Multi-file search & replace of text
Date: Sun, 28 Feb 2010 22:05:33
Message-Id: 201002282144.44660.shrdlu@unlimitedmail.org
In Reply to: Re: [gentoo-user] Multi-file search & replace of text by Stroller
1 On Sunday 28 February 2010, Stroller wrote:
2
3 > > A starting point could be (after you make a backup of the whole tree)
4 > >
5 > > find /basedir -type f -exec sed -i 's/foo/bar/g' {} +
6 >
7 > Many thanks - that looks great!
8 >
9 > My only concern is that it is unreliable enough that you state the
10 > need to backup first. ;)
11
12 The problem is that with such a command it's very easy to screw up hundreds or
13 thousands of files (depending how many you have in the directory tree) in a
14 non-reversible way, for example due to a slight error in the sed command.
15
16 Hence the suggestion of backing up before trying. Alternatively, you can
17 supply an extension to the -i option, as in -i.bak for example, to have sed
18 create backup copies of the changed files (which you can then remove when
19 you've made sure the changes have been successful).