Command and permission errors
Quick answer
Begin with the exact failed command, exit status, affected identity and working directory. A command lookup failure is different from an executable or file-access failure.
Reproduce the problem with the same ordinary identity and directory, using a harmless fixture if possible. Check whether the executable was found before investigating its permissions and arguments. Do not use administrative privilege merely to hide a diagnosis.
Prepare the practice environment
Run python3 lab-fixtures/troubleshooting/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not change live services, mounts, policies or resource limits. All supplied records are fictional; no host incident records are collected. Review the lab guide.
Prerequisites
Review: Performance experiments, Packet capture and VPN concepts, Backup verification and restore.
How it works
In Bash, 127 conventionally means command not found and 126 means a found command could not execute. A program may also return these values itself. Use type -a and command -v to inspect lookup; an alias or function can shadow an executable. For an absolute or relative path, inspect the file mode and each parent directory with stat and namei -l. Directory search permission is needed to traverse a path. A missing interpreter in a shebang, a noexec mount, ACLs or mandatory policy can also prevent execution. Compare the intended identity with id; avoid blindly adding execute rights or using sudo. In the private lab, the owner can restore an intentionally missing execute bit; on a managed system obtain approval and change only the intended mode. Record the old mode so it can be restored. Verify with the original command under the original identity. Prevent recurrence by documenting dependencies and testing permissions during deployment.
Try the examples
if bm_no_such_command_26 2>/dev/null; then exit 1; else rc=$?; fitest "$rc" = 127printf 'lookup exit %s\n' "$rc"The deliberately nonexistent command fails in a clean shell; capture its status immediately.
Expected stdout:
lookup exit 127stat -c '%a' ./report.shif ./report.sh 2>/dev/null; then exit 1; else rc=$?; fitest "$rc" = 126printf 'execution exit %s\n' "$rc"The existing script has no execute bit. This is not a missing command.
Expected stdout:
600execution exit 126The helper copies the sample to a temporary directory, reproduces failure, changes only owner execute, and checks the output. Original remains unchanged.
Expected stdout:
denied 126; owner execute restored; verifiedCommon mistakes
Do not run chmod 777 or use root as a universal fix. A directory needs search permission, not just read permission; check identity and path first.
Practice
Run the three examples in separate fresh fixtures. Explain 126 versus 127, identify the missing mode bit, and verify the repaired copy without changing the source.
Related references
Study: type, namei, stat. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Command and permission errors — Knowledge Check
Apply troubleshooting concepts to synthetic fixtures and VM-only scenarios.
Which status does Bash conventionally return for missing commands?
A file exists with mode 600. What is missing for direct execution by its owner?
Which command displays each path component?
How should a fix be verified?