Sudo cd and sudo ll command error

  

Recently, a friend asked me why the sudo cd and sudo ll login commands have the following prompts:

sudo: ll: command not found sudo: cd: command not found


Running other commands, such as sudo ls, will work fine.


In a nutshell, it can be understood that sudo can only execute commands that come with the system, but not other programs. Such as ll, cd, etc. are brought by the shell.

sudo is a program used to enhance the user's permissions. Entering sodu in linux is to call this program to enhance permissions. The shell is a command parser, sudo cd is wrong, because cd is built into the shell. , not in the system, sudo can run the system with the command, but can not use the commands in a software in the system.

cd is the internal command of the shell. The so-called shell is an interactive application. When the shell executes an external command, it forks a child process through fork/exec and then executes the program. Sudo means to fork a process with someone else's privileges and run the program. And cd is an internal command, that is, it is run directly by the shell, not a fork process. Of course, you can't upgrade the permissions of the process in the current process (in fact, it can be, but it is written in the code when programming, and then compiled, and our shell does not have this function, otherwise it is not too dangerous?)
< In addition, if you want to configure the sudo command, you can use visudo to configure it under the root user.

Copyright © Windows knowledge All Rights Reserved