gpt4 book ai didi

linux - 使用 shell 脚本搜索和替换文件内容

转载 作者:太空宇宙 更新时间:2023-11-04 10:38:00 26 4
gpt4 key购买 nike

我想搜索并替换文件中的特定值,这里是文件的内容

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>

我想用 DocumentRoot/var/www/html/centos 替换 DocumentRoot/var/www/html

我尝试了以下方法

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

这行不通,谁能给我指出正确的方向。

谢谢

最佳答案

您要替换的行是:

DocumentRoot "/var/www/html"

它包含双引号。 sed 命令不包含双引号。尝试:

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

关于linux - 使用 shell 脚本搜索和替换文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36517830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com