Specimens: sudo: cd: command not found
cd在suse上仅是shell builtin, sudo仅仅执行的executable(外部命令), 路径由 /etc/sudoers 的Defaults secure_path = /path1:/path2 指定
There are two ways that it "won't work", depending on your OS:
-
If your OS follows POSIX, then running
sudo cd
will cause the external command "cd" (usually located at/usr/bin/cd
) to execute in a forked process as the root user. That process changes directories successfully. Once that process is done, you will be returned to your regular shell, which is still in the directory where it started.So
sudo cd
runs without error, but does not change the current working directory of your current shell.(reference: this answer)
-
Otherwise, running
sudo cd
will cause the following to happen. Your computer will look through your PATH, trying to find an executable named "cd". It will not find one. (only the shell built-in command "cd" exists, and that is not an executable file). Hence, you get an error. (On Ubuntu, I get the error messagesudo: cd: command not found
.)So
sudo cd
runs with error.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-11-02 Systemd Service Type
2020-11-02 MySQL查看当前数据库 和 用户
2020-11-02 cmd xcopy
2020-11-02 shell miscellanies