AI Learning Hub › Learn AI › Self-Paced Courses › Terminal on Mac: Reading Commands Before You Run Them › When Something Goes Wrong
Module 8 ยท Beginner
When Something Goes Wrong
Four error messages worth recognizing, how to stop a command that is still running, and why sudo deserves a pause rather than a reflex.
By the end
- Read four common error messages as diagnoses
- Tell which program is complaining
- Stop a command that is still running
- Say what
sudodoes and why it deserves a pause
Most terminal errors are short, accurate and completely opaque until somebody tells you what they mean. Four of them cover the great majority of what a beginner runs into, and each one points at a different kind of problem.
What each one is telling you
- No such file or directory
- The path did not lead anywhere. Usually a typo, or the right name in the wrong folder. Run
pwdandlsbefore assuming the file is missing — most of the time you are somewhere else. - command not found
- The shell looked for a program by that name and found none. A typo, or a program that is not installed. Note the
zsh:at the front: this message comes from the shell, not from a program, because no program ever started. - Is a directory
- The path is real but it is a folder, and this command wanted a file.
catcannot print a folder. Often the fix is an option, likecp -R, or a different command entirely. - Permission denied
- The file or folder is real, and your account is not allowed to do that with it. This is a statement about access, not about the command being wrong.
That last one deserves a sentence of its own, because the most common response to it is the wrong one.
Permission denied is not an instruction to try again with more force. It is information. Something is protected, and the useful question is why — are you in a folder that belongs to the system, did you mean a different path, is this file one you should be modifying at all? Reaching for sudo to make the message go away skips that question entirely.
Stopping something that is still running
Most commands finish instantly. Some keep going — searching a very large folder, or running a program that waits for input. When the prompt has not come back and you want out, press Control+C.
What that does is specific. Control+C sends the interrupt character, and macOS’s terminal documentation describes it as generating “a SIGINT signal which is sent to all processes in the foreground process group” — in plain terms, a request to the thing currently running that it should stop.
The important part is what it does not do.
Control+C is not undo. It stops the command from continuing. Anything the command already did — files copied, files removed, a file already overwritten — stays done. Interrupting a removal halfway through leaves you with half a removal, not with everything back.
That distinction is why the rest of this course is about reading commands before running them. Stopping is available; reversing generally is not.
sudo
You will meet this prefix, usually in instructions found online and sometimes in output from an AI tool. Its manual describes it as allowing “a permitted user to execute a command as the superuser or another user, as specified by the security policy.”
In practice it means: run this with the restrictions lifted. It will ask for your Mac password, and the command then does things your account normally could not.
Three things worth holding at once. sudo is a normal tool and plenty of legitimate instructions use it. It also removes the protection that would otherwise have stopped a mistake. And a command you did not write, which starts with sudo, is asking for considerably more trust than the same command without it.
The habit worth building, then, is a pause rather than a refusal:
When a command starts with sudo, read the whole line before typing your password. Not just the first word — the paths, the options, the wildcards, everything after it. The elevation applies to all of it.
Nothing in this course needs sudo. No exercise uses it and you will not be asked for a password anywhere.
A note on command not found
When you type a command name, the shell does not search your whole disk. It looks through a specific list of folders, which Apple’s documentation describes this way: “The list of known folders is stored in the shell’s PATH environment variable.”
That is enough to explain the message. A program can be installed on your Mac and still produce command not found, because it is not in one of the folders the shell checks. Fixing that is a later topic; recognizing it is this one.
Exercise: produce each error on purpose
From ~/terminal-practice, run each of these and write one sentence saying what the computer was telling you.
Try it — all four fail harmlessly
cat nope.txt cd nowhere notacommand cat cases
Then one more, which you should read rather than run: sudo rm -r output. Name every reason that line deserves a second look before anyone types a password into it.
Check the last one
Four reasons, and they stack. It removes rather than reads. It is recursive, so it takes the folder and everything in it. The path is relative, so what it actually deletes depends entirely on which folder you are standing in when you run it. And it is elevated, so the permissions that might have stopped it do not apply.
None of those four is visible from the word sudo alone. You get them by reading the rest of the line, which is the entire point of the next module.