The reason why command not found occurs when you add sudo before executing some commands in Linux __linux

Source: Internet
Author: User
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.