2016-04-09 6 views
0

Ich möchte suchen und zu bestimmten Wert in einer Datei ersetzen ersetzen, hier ist der Inhalt der DateiSuche und Dateiinhalt mit Shell-Skript

filename: /etc/httpd/conf/httpd.conf 
# 
# Deny access to the entirety of your server's filesystem. You must 
# explicitly permit access to web content directories in other 
# <Directory> blocks below. 
# 
<Directory /> 
    AllowOverride none 
    Require all denied 
</Directory> 

# 
# Note that from this point forward you must specifically allow 
# particular features to be enabled - so if something's not working as 
# you might expect, make sure that you have specifically enabled it 
# below. 
# 

# 
# DocumentRoot: The directory out of which you will serve your 
# documents. By default, all requests are taken from this directory, but 
# symbolic links and aliases may be used to point to other locations. 
# 
DocumentRoot "/var/www/html" 

# 
# Relax access to content within /var/www. 
# 
<Directory "/var/www"> 
    AllowOverride None 
    # Allow open access: 
    Require all granted 
</Directory> 

Ich möchte ersetzen DocumentRoot /var/www/html mit DocumentRoot /var/www/html/centos

Ich habe versucht, die folgenden

sudo sed -i "s#DocumentRoot /var/www/html#DocumentRoot /var/www/html/centos#g" /etc/httpd/conf/httpd.conf 

Dies funktioniert nicht, kann mir jemand in die richtige Richtung zeigen.

Dank

Antwort

1

Die Linie, die Sie ersetzen möchten, ist:

DocumentRoot "/var/www/html" 

Es enthält Anführungszeichen. Der Befehl sed enthält keine doppelten Anführungszeichen. Versuchen Sie:

sudo sed -i 's#DocumentRoot "/var/www/html"#DocumentRoot "/var/www/html/centos"#g' /etc/httpd/conf/httpd.conf 
+1

lol - 48 Sekunden zu spät :) – isedev

0

Nevermind, ich es herausgefunden, ich doppelte Anführungszeichen fehlt, arbeitete folgenden Befehl

sudo sed -i 's#DocumentRoot "/var/www/html"#DocumentRoot "/var/www/html/centos"#g' /etc/httpd/conf/httpd.conf