Tao
Tao

目录

sudo命令无法执行解决办法

目录

当我们运行 sudo cd /var/lib/xxx 提示"command not found". 目前有两种解决方式:

  1. sudo -s
  2. sudo -D

sudo -s 选项可以用来以特权身份运行一个 shell。以下是正确的用法:

shell

sudo -s
cd /path/to/directory

使用 sudo -s 命令会启动一个具有特权的 shell 会话。一旦进入特权的 shell,您可以使用 cd 命令来切换到所需的目录。

请将 /path/to/directory 替换为您要导航到的实际目录路径。

sudo 的 -D 选项可用于在指定目录中运行命令。以下是正确的用法:

shell

sudo -D /path/to/directory command

在这个命令中,将 /path/to/directory 替换为您想要在其中运行命令的实际目录路径,并将 command 替换为您想要在该目录中执行的命令。

例如,如果您想要在 /var/www/html 目录中以根用户权限运行 ls 命令,可以使用:

shell

sudo -D /var/www/html ls

这将在 /var/www/html 目录中以根用户身份运行 ls 命令。