参考至https://blog.csdn.net/xiaotengyi2012/article/details/6953494
问题描述
:~# sudo cd /root
sudo:cd:command not found
:~# sudo ls /root/*
no such file of directory
:~# sudo ls /root (成功运行)
原因解释
引用一段比较好的英文解释
cd is a shell built-in command. It cannot be run in a child process. The child process simply cannot change the working directory of its parent shell process.
Redirection also does not work with sudo for the same reason (redirection being a shell “thing”)
注:sudo 是一种程序,用于提升用户的权限,在linux中输入sodu就是调用这个程序提升权限,shell是一个命令解析器,sudo cd是错误的,因为cd是shell内置的,不是系统里面的,sudo可以运行系统带的命令,但无法用系统中一个软件中的命令。
解决方法
获取root权限:
+ su root
+ sudo -s
退出:
- exit
- ctrl+D