Why command not found appears when you add sudo before executing some commands in Linux
When we use sudo to execute a CD, LS, and so on, the command not found prompt appears:
sudo cd/home/michael
Sudo:command not found
We know that when you execute a linux command, if you precede it with sudo, you are executing as root. But there is a prerequisite for this is that only those Linux built-in system commands can be executed in such a form, and you cannot use sudo for root permissions for Shell built-in commands or other user-defined commands, aliases, and so on. Why, then? In detail, the process of sudo hidden behind the scenes to understand.
Because when executing a command in sudo under Linux, a subprocess (child process) is fork on the basis of the original process (parent process), which is executed with root permissions. Then, in the subprocess, execute the command you followed in sudo.
Non-system built-in commands are rejected in a child process that cannot invoke some commands that involve the state of the parent process. This is why the command not found appears. Specifically, when we execute:
sudo cd/home/michael
In this shell process (called PP, which represents the parent process) fork a subprocess (called CP, which represents the child process), it is not possible to change the directory of PP in CP.
sudo ls/home/michael
sudo after the PP produced CP,CP is unable to obtain the contents of the Directory of PP (specifically, read the directory block data, see "Liuda's Linux Travels • Basic article (2) Linux file System Inode"). Reprint http://www.cfanz.cn/?c=article&a=read&id=98765