Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
> Replacing text in all files of a directory
post May 28 2008, 04:12 PM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 1
Joined: 28-May 08
Member No.: 13,492

Hey all,

Thanks in advance to anyone who can help me out with this... Here's what I'm trying to do:

Basically I have a webpage (a pretty big one) with a bunch of html/jsp files. Recently, I was asked to change one of the three main directories' name. So instead of now everything's gonna be The problem here's that every link inside my files is gonna be wrong; Instead of linking to /name2 it's gonna link to /name1. Since there are a lot of files I was wondering if there was a way I could do this automatically.

There are a couple of extra things that have to be kept in mind... For instance, these html files might contain the word name1 (i.e. in a paragraph) and I don't want to do any replacing there. I think it should find instances of /name1* and replace them... I think we'd be fine with that...

Am I way over my head or is this possible?
Go to the top of the page
+Quote Post
Start new topic
Replies (1 - 1)
post May 28 2008, 08:20 PM
Post #2

Its GNU/

Group: Support Specialist
Posts: 1,806
Joined: 23-January 03
Member No.: 360

Very easy.

In your favorite text editor.

for i in $( ls *.html); do
sed 'find/replace string goes here' $i

chmod 744 filename (to be executable only by root.)
To execute file:

Use \/name1 in order to use the / in your search string.

BTW typically for most linux distributions you must be root to edit files in the web server's directories.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 19th March 2018 - 07:30 PM