Skip to content

Reading errors and identifying commands

Module
Understanding Commands
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21
On this page

You typed three commands in a row, and none of them worked. This is what is on your screen:

Screen
learner@rootvolt:~/lab$ hed todo.txt
Command '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.txt
cat: invalid option -- 'N'
Try 'cat --help' for more information.
learner@rootvolt:~/lab$ cat Documents/note.txt
cat: Documents/note.txt: No such file or directory

The 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.

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.

Take the first line from the opening:

Terminal window
hed todo.txt
Error output
Command '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:

Terminal window
head todo.txt
Output
Install Ubuntu
Verify the ISO checksum
Take a snapshot

You 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 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?

Terminal window
cat -N todo.txt
Run it, then compare with your guess
Error output
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:

Terminal window
cat -n todo.txt
Output
1 Install Ubuntu
2 Verify the ISO checksum
3 Take a snapshot

A long option that does not exist gives a slightly different message, with the whole word quoted:

Terminal window
cat --numbers todo.txt
Error output
cat: 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:

Terminal window
cat Documents/note.txt
Error output
cat: Documents/note.txt: No such file or directory

cat 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:

Error output
ls: cannot access 'Documents/note.txt': No such file or directory
head: cannot open 'Documents/note.txt' for reading: No such file or directory

The 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:

Terminal window
ls Documents
Output
notes.txt report.txt

The file is notes.txt, with an s. Change that one word:

Terminal window
cat Documents/notes.txt
Output
Buy printer paper
Renew lab VM snapshot

Tab from lesson B04.2 prevents this mistake, because it only completes names that exist.

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.

A wrong command name and a wrong option, and the smallest fix for each
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21. Each error points at one word: the command name or the option. Changing only that word makes the command work.
Steps (13)
  1. Type hed todo.txt — A typo in the command name
  2. Press Enter
  3. 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>
  4. Type head todo.txt — Fix the name; keep the rest
  5. Press Enter
  6. Output: Install Ubuntu Verify the ISO checksum Take a snapshot
  7. Type cat -N todo.txt — A capital letter where cat expects a lowercase one
  8. Press Enter
  9. Output: cat: invalid option -- 'N' Try 'cat --help' for more information.
  10. Type cat -n todo.txt — Fix the option; keep the rest
  11. Press Enter
  12. Output: 1 Install Ubuntu 2 Verify the ISO checksum 3 Take a snapshot
  13. 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.

A wrong path and its smallest fix
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--

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21. The error names the path that does not exist. Changing only the path makes the command work.
Steps (7)
  1. Type cat Documents/note.txt — One letter missing from the path
  2. Press Enter
  3. Output: cat: Documents/note.txt: No such file or directory
  4. Type cat Documents/notes.txt — Fix the path; keep the rest
  5. Press Enter
  6. Output: Buy printer paper Renew lab VM snapshot
  7. 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.

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:

Terminal window
type head
Output
head is /usr/bin/head

head 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:

Output
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.

Terminal window
type cd
Output
cd is a shell builtin

A 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?

Terminal window
type ls
Run it, then compare with your guess
Output
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.

command -v asks the same question and prints a shorter answer:

Terminal window
command -v head
command -v cd
command -v ls
Output
/usr/bin/head
cd
alias 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.

Asking Bash what a name is with type and command -v
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab system, Ubuntu Desktop package set), GNU Bash 5.2.21. type and command -v show that head is a program in /usr/bin, cd is part of Bash, and ls is an alias.
Steps (19)
  1. Type type head — A program stored in a file
  2. Press Enter
  3. Output: head is /usr/bin/head
  4. Type type cd — A command built into Bash
  5. Press Enter
  6. Output: cd is a shell builtin
  7. Type type ls — A short name for a longer command
  8. Press Enter
  9. Output: ls is aliased to `ls --color=auto'
  10. Type command -v head — The same questions, shorter answers
  11. Press Enter
  12. Output: /usr/bin/head
  13. Type command -v cd
  14. Press Enter
  15. Output: cd
  16. Type command -v ls
  17. Press Enter
  18. Output: alias ls='ls --color=auto'
  19. 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?

Terminal window
type hed
Error output
bash: type: hed: not found

command -v hed prints nothing at all. Nothing printed means no command has that name.

A path error that starts with bash:.

Terminal window
cd Documnets
Error output
bash: cd: Documnets: No such file or directory

The 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.

Terminal window
head -n
Error output
head: 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.

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::

Error output (without command-not-found)
bash: hed: command not found

Read 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.

Many web pages answer “which program is this?” with the command which. Compare it with type:

Terminal window
which ls
Output
/usr/bin/ls

which 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.

Goal: Fix three broken commands from someone’s notes, changing one word in each, then find out what three names are.

  1. 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.txt
    • ls --long Documents (it should list Documents in the long format)
    • head -n 1 Documents/reports.txt
  2. Find out whether ll, printf, and mkdir are 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:

Error output
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>
Terminal window
cat Documents/report.txt
Output
Quarterly lab report

ls --long Documents — ls ran and did not accept the option:

Error output
ls: unrecognized option '--long'
Try 'ls --help' for more information.

Search the help text:

Terminal window
ls --help | grep long
Output
Mandatory 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 format
The 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.

Terminal window
ls -l Documents
Output
total 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.txt

head -n 1 Documents/reports.txt — head ran, the option is fine, and the path does not exist:

Error output
head: cannot open 'Documents/reports.txt' for reading: No such file or directory
Terminal window
head -n 1 Documents/report.txt
Output
Quarterly lab report

Step 2:

Terminal window
type ll
type printf
type mkdir
Output
ll is aliased to `ls -alF'
printf is a shell builtin
mkdir is /usr/bin/mkdir

ll 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 as Command '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 option or unrecognized option quotes the option it rejected. Look up the right one with --help or man.
  • No such file or directory names the path that does not exist. Check the real name with ls or Tab.
  • type says whether a name is an external program (and where its file is), a shell builtin, or an alias. command -v gives the same answer in a shorter form.
  • which only searches for files, so trust type to tell you what will run.

Next, Practice: Understanding Commands puts everything from B04.1 to B04.4 to work in one task.