Reading errors and identifying commands
On this page
You typed three commands in a row, and none of them worked. This is what is on your screen:
learner@rootvolt:~/lab$ hed todo.txtCommand 'hed' not found, did you mean: command 'hcd' from deb hfsutils (3.2.6-15build2) command 'hex' from deb basez (1.6.2-3) command 'jed' from deb jed (1:0.99.20~pre.180+dfsg-2) command 'zed' from deb zfs-zed (2.2.2-0ubuntu9.4) command 'hey' from deb hey (0.1.4-2ubuntu0.24.04.3) command 'sed' from deb sed (4.9-2ubuntu0.24.04.1) command 'red' from deb ed (1.19-1) command 'shed' from deb shed (1.15-5) command 'he' from deb node-he (1.2.0-4) command 'ed' from deb ed (1.19-1) command 'head' from deb coreutils (9.4-3ubuntu6.2) command 'hd' from deb bsdextrautils (2.39.3-9ubuntu6.5) command 'med' from deb ncl-ncarg (6.6.2.dfsg.1-3)Try: sudo apt install <deb name>learner@rootvolt:~/lab$ cat -N todo.txtcat: invalid option -- 'N'Try 'cat --help' for more information.learner@rootvolt:~/lab$ cat Documents/note.txtcat: Documents/note.txt: No such file or directoryThe messages look different, but each one points at one word in the line you typed. If you change the wrong word, the command fails again, and you start guessing.
By the end of this lesson, you can find the one word each message complains about and fix only that word. You can also ask Bash what a command name really is.
Before you start
Section titled “Before you start”- Command anatomy (B04.1) to Finding trustworthy help (B04.3).
- The
~/labpractice directory from lesson B04.1 (setup). If you opened another terminal, runcd ~/labfirst.
Read a message in three parts
Section titled “Read a message in three parts”Read each message for three things: who is speaking, which word it names, and what went wrong.
A message that starts with a program name and a colon, such as cat:, comes from that program. When the program speaks, Bash found it and started it, so the command name is fine. The first message in the opening has no program name in front. It names the word you typed, in quotes, and says not found: no program has that name, so no program ran.
The name is wrong: command not found
Section titled “The name is wrong: command not found”Take the first line from the opening:
hed todo.txtCommand 'hed' not found, did you mean: command 'hcd' from deb hfsutils (3.2.6-15build2) command 'hex' from deb basez (1.6.2-3) command 'jed' from deb jed (1:0.99.20~pre.180+dfsg-2) command 'zed' from deb zfs-zed (2.2.2-0ubuntu9.4) command 'hey' from deb hey (0.1.4-2ubuntu0.24.04.3) command 'sed' from deb sed (4.9-2ubuntu0.24.04.1) command 'red' from deb ed (1.19-1) command 'shed' from deb shed (1.15-5) command 'he' from deb node-he (1.2.0-4) command 'ed' from deb ed (1.19-1) command 'head' from deb coreutils (9.4-3ubuntu6.2) command 'hd' from deb bsdextrautils (2.39.3-9ubuntu6.5) command 'med' from deb ncl-ncarg (6.6.2.dfsg.1-3)Try: sudo apt install <deb name>Read the first line. 'hed' is the name you typed, and not found is what went wrong: no command has that name. Bash looks for programs in a fixed list of directories, called the PATH; lesson B08.4 explains that search. When the search finds nothing, Bash on Ubuntu Desktop passes the name to a helper from the package command-not-found, and the helper prints this message.
The lines below the first are guesses: commands with names spelled almost like hed, each with the package it comes from. One of them, head, is the command you meant. The list and its order can differ from one try to the next. The last line suggests installing a package. After a typo, do not: the guesses are chosen only by spelling, and the command you meant is usually installed already.
No program ran, so nobody looked at todo.txt. The smallest fix is the command name and nothing else:
head todo.txtInstall UbuntuVerify the ISO checksumTake a snapshotYou do not need to retype the line: press Up and edit the one word, as in lesson B04.2. Tab also helps. If two presses of Tab after the start of a name add nothing and list nothing, no command starts that way.
The option is wrong: invalid option
Section titled “The option is wrong: invalid option”The second command was cat -N todo.txt. Guess first: which part of its message tells you what went wrong? And who prints it, Bash or cat?
cat -N todo.txtRun it, then compare with your guess
cat: invalid option -- 'N'Try 'cat --help' for more information.The message starts with cat:, so cat printed it. Bash found the program and started it, and cat then checked its options. invalid option is what went wrong, and 'N' is the exact character it did not accept. Everything else on the line is fine.
The second line names the guide from lesson B04.3. In cat --help, the option that numbers lines is -n, with a lowercase n. As with -a and -A in lesson B04.1, case matters. Change that one letter:
cat -n todo.txt 1 Install Ubuntu 2 Verify the ISO checksum 3 Take a snapshotA long option that does not exist gives a slightly different message, with the whole word quoted:
cat --numbers todo.txtcat: unrecognized option '--numbers'Try 'cat --help' for more information.unrecognized option means the same thing as invalid option: this program has no option with that spelling. The long form in cat --help is --number, without the s.
The path is wrong: No such file or directory
Section titled “The path is wrong: No such file or directory”The third command was cat Documents/note.txt:
cat Documents/note.txtcat: Documents/note.txt: No such file or directorycat printed it, so the command name is fine, and the message says nothing about options. The name in the middle, Documents/note.txt, is what cat tried to open. The end says it does not exist.
Each program words this message a little differently. Here are ls and head with the same path:
ls: cannot access 'Documents/note.txt': No such file or directoryhead: cannot open 'Documents/note.txt' for reading: No such file or directoryThe ending is the same, and the path is always in the message. Look at that path, not at the program.
To see the names that do exist, list the directory:
ls Documentsnotes.txt report.txtThe file is notes.txt, with an s. Change that one word:
cat Documents/notes.txtBuy printer paperRenew lab VM snapshotTab from lesson B04.2 prevents this mistake, because it only completes names that exist.
Three messages, three places to fix
Section titled “Three messages, three places to fix”The table has one more row, for a message you have already met in lesson B03.3: Permission denied.
| The message says | Who prints it | The wrong word is | Smallest fix |
|---|---|---|---|
Command '…' not found or command not found |
Bash, or its command-not-found helper | The command name | Correct the name; do not install a suggested package |
invalid option or unrecognized option |
The program | The option it quotes | Look it up in --help or man |
No such file or directory |
Usually the program | The path in the message | Check the name with ls or Tab |
Permission denied |
The program | None: the path is right, but your account may not do this | Read whether the task needs root, as in lesson B03.3 |
The two replays below run the three commands from the opening, each followed by its corrected version. The first shows the command name and the option.
learner@rootvolt:~/lab$ hed todo.txtCommand 'hed' not found, did you mean:
command 'ed' from deb ed (1.19-1)
command 'hey' from deb hey (0.1.4-2ubuntu0.24.04.3)
command 'red' from deb ed (1.19-1)
command 'sed' from deb sed (4.9-2ubuntu0.24.04.1)
command 'zed' from deb zfs-zed (2.2.2-0ubuntu9.4)
command 'he' from deb node-he (1.2.0-4)
command 'med' from deb ncl-ncarg (6.6.2.dfsg.1-3)
command 'shed' from deb shed (1.15-5)
command 'jed' from deb jed (1:0.99.20~pre.180+dfsg-2)
command 'hex' from deb basez (1.6.2-3)
command 'hd' from deb bsdextrautils (2.39.3-9ubuntu6.5)
command 'hcd' from deb hfsutils (3.2.6-15build2)
command 'head' from deb coreutils (9.4-3ubuntu6.2)
Try: sudo apt install <deb name>learner@rootvolt:~/lab$ head todo.txtInstall Ubuntu
Verify the ISO checksum
Take a snapshotlearner@rootvolt:~/lab$ cat -N todo.txtcat: invalid option -- 'N'
Try 'cat --help' for more information.learner@rootvolt:~/lab$ cat -n todo.txt 1 Install Ubuntu
2 Verify the ISO checksum
3 Take a snapshotlearner@rootvolt:~/lab$ Steps (13)
- Type
hed todo.txt— A typo in the command name - Press Enter
- Output:
Command 'hed' not found, did you mean: command 'ed' from deb ed (1.19-1) command 'hey' from deb hey (0.1.4-2ubuntu0.24.04.3) command 'red' from deb ed (1.19-1) command 'sed' from deb sed (4.9-2ubuntu0.24.04.1) command 'zed' from deb zfs-zed (2.2.2-0ubuntu9.4) command 'he' from deb node-he (1.2.0-4) command 'med' from deb ncl-ncarg (6.6.2.dfsg.1-3) command 'shed' from deb shed (1.15-5) command 'jed' from deb jed (1:0.99.20~pre.180+dfsg-2) command 'hex' from deb basez (1.6.2-3) command 'hd' from deb bsdextrautils (2.39.3-9ubuntu6.5) command 'hcd' from deb hfsutils (3.2.6-15build2) command 'head' from deb coreutils (9.4-3ubuntu6.2) Try: sudo apt install <deb name> - Type
head todo.txt— Fix the name; keep the rest - Press Enter
- Output:
Install Ubuntu Verify the ISO checksum Take a snapshot - Type
cat -N todo.txt— A capital letter where cat expects a lowercase one - Press Enter
- Output:
cat: invalid option -- 'N' Try 'cat --help' for more information. - Type
cat -n todo.txt— Fix the option; keep the rest - Press Enter
- Output:
1 Install Ubuntu 2 Verify the ISO checksum 3 Take a snapshot - Find the word the message names, change only that word, and run the line again.
In words: hed todo.txt gives Command 'hed' not found and a list of similar names, and head todo.txt prints the three lines of todo.txt. cat -N todo.txt gives invalid option -- 'N', and cat -n todo.txt prints the same lines numbered.
The second shows the path.
learner@rootvolt:~/lab$ cat Documents/note.txtcat: Documents/note.txt: No such file or directorylearner@rootvolt:~/lab$ cat Documents/notes.txtBuy printer paper
Renew lab VM snapshotlearner@rootvolt:~/lab$ Files ~/lab
- ~
- lab/cwd
- Documents/
- notes.txtargument-rw-r--r--
- report.txt-rw-r--r--
- .draft.txthidden-rw-r--r--
- projects/
- todo.txt-rw-r--r--
Steps (7)
- Type
cat Documents/note.txt— One letter missing from the path - Press Enter
- Output:
cat: Documents/note.txt: No such file or directory - Type
cat Documents/notes.txt— Fix the path; keep the rest - Press Enter
- Output:
Buy printer paper Renew lab VM snapshot - The message names the path that does not exist. Change only the path.
In words: cat Documents/note.txt gives No such file or directory, and cat Documents/notes.txt prints the two lines of the file.
Ask Bash what a name is
Section titled “Ask Bash what a name is”The command names you have used are not all the same kind of thing. The command type takes a name and tells you which kind it is:
type headhead is /usr/bin/headhead is a program stored as a file: the file head in the directory /usr/bin. A program in its own file is called an external program. /usr/bin holds many of the programs you run; module B05 tours the system directories.
If you ran head earlier in this terminal, for example to fix the first error in this lesson, the answer looks slightly different:
head is hashed (/usr/bin/head)Hashed means that Bash remembers where it found the program the last time it ran. The file is the same.
type cdcd is a shell builtinA builtin is a command that is part of Bash itself. There is no separate file to run. This is why lesson B04.3 found no man page for cd, and why help cd described it instead.
Now ls, the command you have used most in this course. Guess first: is ls an external program, like head, or a builtin, like cd?
type lsRun it, then compare with your guess
ls is aliased to `ls --color=auto'Neither. On Ubuntu, ls is an alias: a short name that Bash replaces with a longer command before it runs anything. Ubuntu’s default ~/.bashrc file sets this alias, so that ls shows names in color. When you type ls Documents, Bash runs ls --color=auto Documents.
A shorter answer with command -v
Section titled “A shorter answer with command -v”command -v asks the same question and prints a shorter answer:
command -v headcommand -v cdcommand -v ls/usr/bin/headcdalias ls='ls --color=auto'For an external program, it prints the full path to the file. For a builtin, it prints only the name. For an alias, it prints the alias as you would define it. Use type when you want a sentence you can read, and command -v when you want only the path.
learner@rootvolt:~/lab$ type headhead is /usr/bin/headlearner@rootvolt:~/lab$ type cdcd is a shell builtinlearner@rootvolt:~/lab$ type lsls is aliased to `ls --color=auto'learner@rootvolt:~/lab$ command -v head/usr/bin/headlearner@rootvolt:~/lab$ command -v cdcdlearner@rootvolt:~/lab$ command -v lsalias ls='ls --color=auto'learner@rootvolt:~/lab$ Steps (19)
- Type
type head— A program stored in a file - Press Enter
- Output:
head is /usr/bin/head - Type
type cd— A command built into Bash - Press Enter
- Output:
cd is a shell builtin - Type
type ls— A short name for a longer command - Press Enter
- Output:
ls is aliased to `ls --color=auto' - Type
command -v head— The same questions, shorter answers - Press Enter
- Output:
/usr/bin/head - Type
command -v cd - Press Enter
- Output:
cd - Type
command -v ls - Press Enter
- Output:
alias ls='ls --color=auto' - type answers in a sentence; command -v prints only what Bash would run.
In words: type head prints head is /usr/bin/head, type cd prints cd is a shell builtin, and type ls prints that ls is aliased to ls --color=auto. Then command -v prints /usr/bin/head, cd, and alias ls='ls --color=auto'.
Both commands also answer the question from the first section: does this name exist at all?
type hedbash: type: hed: not foundcommand -v hed prints nothing at all. Nothing printed means no command has that name.
Mistakes to recognize
Section titled “Mistakes to recognize”A path error that starts with bash:.
cd Documnetsbash: cd: Documnets: No such file or directoryThe message starts with bash:, but this is not a command not found error. cd is a builtin, so Bash itself prints the message and adds the name cd. Read the end: the path Documnets does not exist. The directory is Documents.
A missing value, not a wrong option.
head -nhead: option requires an argument -- 'n'Try 'head --help' for more information.The option -n exists, so do not look for another one. It needs a value, the number of lines, and none came after it. Lesson B04.1 explains options that need a value.
Good to know
Section titled “Good to know”The message on systems without command-not-found. Some systems do not have the package command-not-found, for example the official Ubuntu container image. There, Bash prints the message itself, in one line that starts with bash::
bash: hed: command not foundRead it the same way: Bash is speaking, the word is hed, and command not found is what went wrong. The fix is the same too: correct the name. Module B12 covers installing software.
No guesses, one line. When the helper finds no command with a similar name, it prints only one line, such as LS: command not found and ls-l: command not found in lesson B04.1. The word before the colon is the name you typed, not a program speaking.
Aliases on other systems. Another system can have different aliases or none, so type ls may give a different answer there.
Security Angle
Section titled “Security Angle”Many web pages answer “which program is this?” with the command which. Compare it with type:
which ls/usr/bin/lswhich is a separate program. It searches only the PATH directories for a file with that name, and it knows nothing about the aliases and builtins of your shell. So which cd prints nothing, and which ls names the file, not the alias that runs when you type ls.
Here the difference is harmless: the alias only adds color. But on an account you did not set up, a familiar name such as ls or sudo can be an alias for a different command, and which would not show it. type asks the shell that will run the command, so on a system you do not control, ask type.
Try it yourself
Section titled “Try it yourself”Goal: Fix three broken commands from someone’s notes, changing one word in each, then find out what three names are.
- Run each line, read the message, and decide which word is wrong. Then fix only that word and run the line again.
cta Documents/report.txtls --long Documents(it should listDocumentsin the long format)head -n 1 Documents/reports.txt
- Find out whether
ll,printf, andmkdirare external programs, builtins, or aliases.
Expected: The first and third commands print Quarterly lab report. The second lists notes.txt and report.txt with sizes and dates. Step 2 gives one of each kind.
Hint
Start with who is speaking: does the message start with a program name, or does it say a command is not found? Then read the end. For the second command, search the help text for the word “long”, as in lesson B04.3.
Solution
cta Documents/report.txt — the message names 'cta' and says not found, so the command name is wrong. cat is one of the guesses:
Command 'cta' not found, did you mean: command 'cat' from deb coreutils (9.4-3ubuntu6.2) command 'ctr' from deb containerd (2.2.1-0ubuntu1~24.04.3) command 'eta' from deb eta (1.0.1-1) command 'sta' from deb opensta (0~20191111gitc018cb2+dfsg-1build1) command 'cba' from deb cba (0.3.6-6build1)Try: sudo apt install <deb name>cat Documents/report.txtQuarterly lab reportls --long Documents — ls ran and did not accept the option:
ls: unrecognized option '--long'Try 'ls --help' for more information.Search the help text:
ls --help | grep longMandatory arguments to long options are mandatory for short options too. --format=WORD across -x, commas -m, horizontal -x, long -l, -G, --no-group in a long listing, don't print group names -l use a long listing formatThe TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT.-l has no long option of its own. The closest is --format=long, which the second line above names. That is why --long fails.
ls -l Documentstotal 8-rw-r--r-- 1 learner learner 40 Oct 1 09:00 notes.txt-rw-r--r-- 1 learner learner 21 Oct 1 09:00 report.txthead -n 1 Documents/reports.txt — head ran, the option is fine, and the path does not exist:
head: cannot open 'Documents/reports.txt' for reading: No such file or directoryhead -n 1 Documents/report.txtQuarterly lab reportStep 2:
type lltype printftype mkdirll is aliased to `ls -alF'printf is a shell builtinmkdir is /usr/bin/mkdirll is an alias from Ubuntu’s ~/.bashrc. printf, which built your practice files in lesson B04.1, is a builtin. mkdir is an external program.
- A message that names a command and says
not found, such asCommand 'hed' not found, means the command name is wrong. No program ran, so fix the name only, and do not install a suggested package. - A message that starts with the program’s name and says
invalid optionorunrecognized optionquotes the option it rejected. Look up the right one with--helporman. No such file or directorynames the path that does not exist. Check the real name withlsor Tab.typesays whether a name is an external program (and where its file is), a shell builtin, or an alias.command -vgives the same answer in a shorter form.whichonly searches for files, so trusttypeto tell you what will run.
Next, Practice: Understanding Commands puts everything from B04.1 to B04.4 to work in one task.
Further reading
Section titled “Further reading”- GNU Bash Reference Manual: Bash Builtin Commands, the entries for
typeandcommand. - GNU Bash Reference Manual: Aliases, and Command Search and Execution, how Bash finds a command and when it reports
command not found. man bash, section SHELL BUILTIN COMMANDS, or the Ubuntu 24.04 bash(1) page.man catandman whichon your system, or the Ubuntu 24.04 cat(1) page online. On Ubuntu,whichcomes from thedebianutilspackage.- GNU Coreutils manual: Common options, including
--help.