【发布时间】:2022-10-23 00:16:32
【问题描述】:
标题中的名字说明了一切。但是,我绝对是 sed 命令最差的。所以我正在尝试编辑以下文件:
/var/www/html/phpMyAdmin/config.inc.php
我想编辑说
$cfg['Servers'][$i]['AllowRoot'] = false;
进入以下
$cfg['Servers'][$i]['AllowRoot'] = true;
它有很多特殊字符等等,我对 sed 的工作原理一无所知。所以这里有一些我试图专门编辑这一行的命令。
sed -i "/*.AllowRoot.*/\$cfg['Servers'][\$i]['AllowRoot'] = true;/" /var/www/html/phpMyAdmin/config.inc.php
sed -i "/*.AllowRoot.*/$cfg['Servers'][$i]['AllowRoot'] = true;/" /var/www/html/phpMyAdmin/config.inc.php
# this one finds the line successfully and prints it so I know it's got the right string:
sed -n '/AllowRoot/p' /var/www/html/phpMyAdmin/config.inc.php
sed -i "s/'AllowRoot|false'/'AllowRoot|true'/" /var/www/html/phpMyAdmin/config.inc.php
我完全不知道自己在做什么,除了感觉最后一个命令拆分'AllowRoot|false' 确保两个都必须出现在句子中才能返回之外,我并没有学到很多东西。所以按照我的逻辑,我认为将单词false 更改为true 会实现这一点,但没有。其他命令返回......充其量是奇怪的结果,甚至清空文件。或者那是我没有在这里写下的命令之一,我在尝试了 50 次后就迷失了方向。这里的解决方案是什么?
【问题讨论】:
-
是的,我知道我不应该使用 root 登录到 phpmyadmin,但是在您使用它的短时间内很方便,然后目标是再次将标志设置为 false。
-
如果你“完全不知道 [你] 在做什么”,也许正确的起点是基本的
sed教程。一点知识是危险的。在零知识的情况下执行命令可能是灾难性的。