Finding trustworthy help
On this page
ls shows what is in ~/lab. ls Documents shows what is in Documents. You want both in one listing: everything in ~/lab, and everything inside each directory in it. None of the options you know does that.
ls has many more options, but guessing letters is not a method: one wrong letter, and the command does something you did not ask for. The answer is already on your computer. Each program comes with a description of its options, written for the version you have. By the end of this lesson, you can open that description, search it, and run the option it names.
Before you start
Section titled “Before you start”- Command anatomy (B04.1) and Editing and completing commands (B04.2).
- The
~/labpractice directory from lesson B04.1 (setup). If you opened another terminal, runcd ~/labfirst.
Ask the program with –help
Section titled “Ask the program with –help”Many programs print a short guide to themselves when you give them the option --help:
ls --helpUsage: ls [OPTION]... [FILE]...List information about the FILEs (the current directory by default).Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and ..…Full documentation <https://www.gnu.org/software/coreutils/ls>or available locally via: info '(coreutils) ls invocation'Read the first line. Usage: shows the shape of the command: the name ls, then options, then files. Square brackets mean the part is optional. The three dots mean you can give more than one. In this guide, FILE means any name, a directory included.
Below that, each option gets one line: the short form, the long form, and what it does. You know the first two from lesson B04.1.
The line about “mandatory arguments” means: when the long form of an option needs a value, the short form needs one too. You saw this with head, where -n and --lines both need a number.
There is one problem. On the lab system, ls --help prints 138 lines. They scroll past, and you see only the end.
Open the manual page
Section titled “Open the manual page”The full description of a program is its manual page, or man page for short. The command man opens it:
man lsThis time the prompt does not come back. The page fills the terminal, and it starts like this:
LS(1) User Commands LS(1)
NAME ls - list directory contents
SYNOPSIS ls [OPTION]... [FILE]...
DESCRIPTION- NAME says in one line what the program does.
- SYNOPSIS is the same usage line that
--helpprinted. - DESCRIPTION explains the options, one paragraph each: the option names on one line, and the explanation indented below them.
man shows the page in a pager: a program that shows text one screen at a time and waits for your keys. On Ubuntu, the pager is less. The last line of the screen names the page, ls(1), and reminds you that h shows help and q quits.
Move and search inside the page
Section titled “Move and search inside the page”While the page is open, your keys go to the pager, not to Bash. These are the ones you need:
| Key | What it does |
|---|---|
| Space | Show the next screen |
b |
Show the previous screen |
| Down, Up | Move one line |
/, a word, then Enter |
Search forward for the word |
n |
Go to the next match |
N |
Go to the previous match (capital N) |
q |
Quit and return to the prompt |
h |
Show every key the pager knows (q closes it) |
Back to the problem. A directory inside another directory is called a subdirectory. An option that lists them would likely use that word, so search for it:
- Run
man ls. - Type
/subdirectories. The/and the word appear on the last line of the screen. - Press Enter. The pager moves to the first line that contains the word and marks it:
list subdirectories recursively. - The pager puts the match on the top line of the screen, so the option names are just above it, out of view. Press Up once: the line reads
-R, --recursive. - Press
q. The prompt comes back.
If the first match is not the one you want, press n until you reach it.
Recursively means: list each subdirectory, then the ones inside it, and so on, until none are left. Run the option you found:
ls -R.:Documents projects todo.txt
./Documents:notes.txt report.txt
./projects:Each block starts with a directory name and a colon. . is the current directory, ~/lab, and projects is empty. That is the listing you wanted at the start.
Notice the capital letter in -R. Guess first: what does ls -r, with a lowercase r, do?
ls -rRun it, then compare with your guess
todo.txt projects DocumentsSomething else entirely. The manual lists -r, --reverse right above -R: “reverse order while sorting”. As with -a and -A in lesson B04.1, the capital letter makes it a different option.
Search the help text from the prompt
Section titled “Search the help text from the prompt”When you already know the word, you can search without opening the pager:
ls --help | grep subdirectories -R, --recursive list subdirectories recursivelyThe | passes the output of ls --help to the program grep, which prints only the lines that contain subdirectories. Module B09 explains |, and module B10 explains grep. This works best with --help, which puts the option names and their explanation on one line.
learner@rootvolt:~/lab$ lsDocuments projects todo.txtlearner@rootvolt:~/lab$ ls --help | grep subdirectories -R, --recursive list subdirectories recursivelylearner@rootvolt:~/lab$ ls -R.:
Documents projects todo.txt
./Documents:
notes.txt report.txt
./projects:learner@rootvolt:~/lab$ Files ~/lab
- ~
- lab/cwd
- Documents/
- notes.txt-rw-r--r--
- report.txt-rw-r--r--
- .draft.txthidden-rw-r--r--
- projects/
- todo.txt-rw-r--r--
Steps (10)
- Type
ls— The starting point: only the top level of ~/lab - Press Enter
- Output:
Documents projects todo.txt - Type
ls --help | grep subdirectories— Keep only the help lines that contain the word - Press Enter
- Output:
-R, --recursive list subdirectories recursively - Type
ls -R— Use the option the help text named - Press Enter
- Output:
.: Documents projects todo.txt ./Documents: notes.txt report.txt ./projects: - Search the help for a word that describes what you want, then run the option it names.
In words: ls prints Documents projects todo.txt. The search prints the one line that names -R, --recursive. Then ls -R lists ~/lab, ./Documents, and ./projects, each in its own block.
Read the number in ls(1)
Section titled “Read the number in ls(1)”The top line of the page said LS(1). The manual is divided into numbered sections, and the number in parentheses is the section: ls(1) means “the page ls in section 1”. You meet these three most often:
| Section | What its pages describe | Example |
|---|---|---|
| 1 | Programs you run as a user | ls(1) |
| 5 | File formats: what the lines in a file mean | passwd(5) |
| 8 | System administration commands, usually run as root | useradd(8) |
man man lists every section.
One name can have pages in several sections. passwd is the program that changes your password, and also the file /etc/passwd, which lists the accounts on the system. Guess first: which page does man passwd open, the program or the file?
Run it, then compare with your guess
The top line of the page:
PASSWD(1) User Commands PASSWD(1)The program. man looks through the sections in a fixed order, starting with section 1, and opens the first page it finds.
To open a page from another section, put the section number before the name:
man 5 passwdPASSWD(5) File Formats and Configuration PASSWD(5)To see every page with a name before you open one, use man -f:
man -f passwdpasswd (1) - change user passwordpasswd (1ssl) - OpenSSL application commandspasswd (5) - the password fileThe middle page belongs to OpenSSL, a separate set of programs with its own openssl passwd command. The suffix ssl marks a group of pages inside section 1.
Documentation installed with the software
Section titled “Documentation installed with the software”The last lines of ls --help point to a longer manual in a format called Info, read with the program info. GNU programs such as ls and head often have an Info manual that explains more than the man page. The second line names the command that opens it:
info '(coreutils) ls invocation'The chapter about ls opens in a pager, as a man page does. It starts like this:
File: coreutils.info, Node: ls invocation, Next: dir invocation, Up: Directory listing
10.1 ‘ls’: List directory contents==================================The first line names the manual, coreutils.info, and the chapter, ls invocation. Next names the following chapter, and Up the part of the manual it belongs to. Space shows the next screen, and q quits and returns to the prompt.
Some systems do not have the program info. There, the command prints a not found message instead, and the same manual is on the GNU website, at the “Full documentation” address. Module B12 shows how to install programs.
Packages can also put files in /usr/share/doc, in a directory named after the package:
ls /usr/share/doc/bashchangelog.Debian.gz INTRO.gz README.abs-guide README.md.bash_completion.gzCOMPAT.gz NEWS.gz README.commands.gzcopyright POSIX.gz README.Debian.gzinputrc.arrows RBASH README.gzYou find README files, notes on changes (NEWS, changelog), and the license in copyright. Names ending in .gz are compressed; zless followed by the file name opens one in the same pager, with the same keys. These files rarely explain options; the man page does.
Mistakes to recognize
Section titled “Mistakes to recognize”Asking for a page that does not exist. You have already used cd, but:
man cdNo manual entry for cdman found no page with that name in any section. The lab system has no page for cd, because cd is not a separate program: it is part of Bash. Bash describes its own commands with help:
help cdcd: cd [-L|[-P [-e]] [-@]] [dir] Change the shell working directory.…Lesson B04.4 shows how to find out whether a command is part of Bash.
Asking for the wrong section. A section number limits the search to that section:
man 5 lsNo manual entry for ls in section 5The page exists, but only in section 1. Leave out the number, or run man -f ls to see which sections have a page.
One dash in front of help. --help is a long option, so it needs two dashes:
ls -helpls: invalid option -- 'e'Try 'ls --help' for more information.With one dash, ls reads -help as four short options, -h, -e, -l, and -p, and stops at -e, which does not exist. The second line tells you the spelling ls expects.
Good to know
Section titled “Good to know”When you do not know the command name. man -k searches the names and one-line descriptions of every page. The quotes keep the two words together as one search:
man -k 'list directory'dir (1) - list directory contentsls (1) - list directory contentsvdir (1) - list directory contentsValues that differ on your system. The files in /usr/share/doc depend on what is installed, and the date on the last line of a man page depends on the package version.
Security Angle
Section titled “Security Angle”A command on a web page was written for someone else’s system. The same option can mean something different in another version of a program, or in another program with the same name, and the page rarely says which one its author had. The manual on your computer names the version on its last line:
man ls | tail -n 1GNU coreutils 9.4 August 2026 LS(1)tail -n 1 prints only the last line. Compare it with the version of the program itself:
ls --version | head -n 1ls (GNU coreutils) 9.4They match, because Ubuntu installs the page and the program together, in the same package. So before you run a command from a page you do not know, look up each option in your own manual. If an option is missing there, or the manual describes it differently, do not run the command.
Try it yourself
Section titled “Try it yourself”Goal: Print todo.txt with a number in front of each line, using cat from lesson B04.2 and an option you find yourself.
- Open the manual page for
cat. - Search it for a word that the explanation of such an option would contain.
- When you have found the option, quit the page and run it on
todo.txt.
Expected: The three lines of todo.txt, numbered 1 to 3.
Hint
Search for /number. The first match may not be the option you want; read its explanation, then press n for the next match.
Solution
In man cat, /number first finds -b, --number-nonblank: “number nonempty output lines”. Press n for -n, --number: “number all output lines”. The search from the prompt shows both:
man cat | grep number -b, --number-nonblank number nonempty output lines, overrides -n -n, --number number all output linesRun the option:
cat -n todo.txt 1 Install Ubuntu 2 Verify the ISO checksum 3 Take a snapshotcat -b todo.txt prints the same, because todo.txt has no empty lines; -b only skips empty lines when it counts.
--helpprints a short guide to a program’s options. In the usage line, square brackets mean optional and three dots mean “more than one”.manopens the manual page in a pager. Space andbmove by screens,/wordsearches,nandNmove between matches, andqquits.- The number in
ls(1)orpasswd(5)is the manual section.man 5 passwdopens the page from section 5, andman -flists every page with a name. helpdescribes Bash’s own commands, such ascd. Longer manuals may be installed as Info documents and in/usr/share/doc.- Your own man page describes the version you have. Check a copied command’s options there before you run it.
Next, in Reading errors and identifying commands, you read an error message and find out what kind of command a name refers to.
Further reading
Section titled “Further reading”man manandman lesson your system, or the Ubuntu 24.04 manual pages online: man(1) (with the list of sections), less(1), ls(1), cat(1).- GNU Coreutils manual: ls invocation, the Info chapter that
ls --helppoints to. - GNU Bash Reference Manual: Bash Builtin Commands, including
help. - GNU Texinfo: Stand-alone GNU Info, the manual for the
infoprogram. - Debian Policy Manual: Documentation, what packages install in
/usr/share/doc. Ubuntu follows the same layout.