Module 1 · Lesson 4 of 31

Getting help, paths and working fast

Find the answer to any command with man, help, apropos and type, move around the filesystem, understand PATH, and work fast in the shell.

  • Beginner to advanced
  • 13 min read
  • 35 min lab
What you will need

Ubuntu 24.04 (WSL2, a VM, or a container) with a terminal; no special hardware

By the end you can 3 objectives
  • Find the answer to any how-do-I-use-X question with man, help, --help, apropos and type, recording the proof command.
  • Use tab completion, history expansion (!n) and reverse search (Ctrl-R) to re-run commands faster.
  • Navigate the filesystem with absolute and relative paths and perform basic file operations with ls, cd, cp, mv, rm and friends.
Read the lesson below; the video will appear here when published.
01

Getting help on Linux

4 min read

The reference documentation is the manual, organised into numbered sections. Section 1 is user commands, section 2 is system calls, section 3 is library functions, section 4 is device files, section 5 is file formats, section 6 is games, section 7 is miscellaneous overviews, and section 8 is administration commands. To read a page you type man name, and to pick a section you put the number first: man 2 write opens the write system call, while man write opens the messaging command in section 1.

When you know the name, the help ladder is three rungs. For a shell builtin, use the help builtin: help cd. For an external program, try its own quick help first with --help, then the full page with man ls. For the GNU project's alternative hypertext documentation, use info, and for quick community examples, tldr (a separate tool, not always installed).

When you do not know the name, search. apropos -a file system space searches the manual's short descriptions and returns the df page, which reports file system space usage. whatis (the same as man -f) does the reverse: given a name, it lists every section that name appears in.

Here is a worked example, answering the question "what does ls -h do?".

1identify the command

Run type ls. It reports that ls is an external program, so its documentation lives in a man page, not in the shell's help.

2read the quick help

Run ls --help and search the output for -h; it says the flag lists sizes in human-readable form.

3read the full page

Run man ls, press / and type -h to search inside the pager, and read the surrounding options.

4confirm with a test

Run ls -lh and check the sizes; the effect of -h only appears together with -l, which confirms what the page said.

Choosing the right helpKnow thename?type namealias,builtin,file?builtinhelp nameexternalman nameExit from step 1: noapropos -a wordstry theoptionKnow thename?type namealias,builtin,file?Exit from step 1: noapropos -a wordsbuiltinhelp nameexternalman nametry theoption
The decision path for answering any how-do-I-use-X question
Going deeperWhere man pages come from

A man page is source text marked up in the roff language and stored compressed under directories such as /usr/share/man/man1. The man program, part of the man-db package, renders it through groff and pages it with a pager such as less. A background job rebuilds a database of names and one-line descriptions; apropos and whatis query that database, which is why they are fast and why they can only find words the page author actually wrote. The section number exists because one name can have several unrelated meanings: printf in section 1 is the shell and coreutils command, while printf in section 3 is the C library function, and the two share only a name.

No man pages on the board

A minimal embedded image built with BusyBox often omits man, info and even groff to save flash space, so the only help present is each applet's --help text. That is one reason this lesson teaches the --help rung first: it is the one that always exists on the target.

Language settings also change what you see. The LANG and LC_ALL variables control locale, including which language man pages are shown in and, as you will see next, how commands sort their output. Setting LC_ALL=C forces the classic English behaviour, which is a common fix when output looks wrong.

02

Paths, files, and moving around

3 min read

There is one directory tree, with no drive letters. Its root is /, and every file and device hangs off it. pwd prints your current directory, cd changes it, and ls lists. An absolute path starts at the root, such as /etc/passwd; a relative path starts where you are, such as Documents/notes.txt. Two special names work in every directory: . means the current directory and .. means its parent.

Resolve a relative path below:

The relative path notes/linux/lesson1.md from /home/learner resolves to the absolute file /home/learner/notes/linux/lesson1.md; an absolute path like /etc/passwd instead starts from the root /.

  • cwd: /home/learner
  • value: notes/linux/lesson1.md
bash
pwd        # typical output: /home/learner
cd /etc    # absolute path
cd ..      # back to /
ls -la     # long listing including hidden files
ls -lh     # human-readable sizes

Hidden files simply have names beginning with a dot; ls -a reveals them. The -l, -a and -h flags are separate options that can be grouped, so ls -la is ls -l -a.

The single filesystem tree/one tree, no drive lettersbinessential programsetcconfigurationhomelearneryour filesusrmost programsdevdevice filestmptemporary files/one tree, no drive lettersbinessential programsetcconfigurationhomelearneryour filesusrmost programsdevdevice filestmptemporary files
The single tree from /, with configuration, programs, user files and device files

Creating, copying, moving and removing files are all small commands: touch creates an empty file or updates a timestamp, cp copies, mv moves or renames, rm removes, mkdir creates a directory and rmdir removes an empty one. To inspect a file you have file (which identifies its type), cat (which prints the whole file), and head and tail (which print the first or last lines).

bash
mkdir -p notes/linux
touch notes/linux/lesson1.md
file notes/linux/lesson1.md    # typical output: ... empty
echo "hello" > notes/linux/lesson1.md
cat notes/linux/lesson1.md     # prints: hello
head -n 5 /etc/passwd          # first five lines

Two cautions. rm does not move files to a recycle bin, and rm -rf on the wrong path is a classic way to destroy a system, so read the path twice before running it. And cp overwrites silently by default; the -i flag makes it ask first, and -n makes it never overwrite.

Going deeperWhy ls sorts the way it does

The order of a directory listing is not fixed by the alphabet; it is fixed by your locale. The LC_COLLATE variable sets the collation, or sort, rules. In the common en_US.UTF-8 locale, ls ignores case and punctuation when sorting, so Apple, apple and apple2 group together in ways that can surprise you. Setting LC_ALL=C sorts by raw byte value, which is stable and predictable, and is what many scripts do so their output does not depend on the machine's language. This is a real source of confusing bugs: a script that works on your laptop fails on a colleague's machine because the two locales sort differently.

One tree: paths and files
learner@embeddex:~/lab$ # create an empty file
learner@embeddex:~/lab$ touch notes/linux/lesson1.md
learner@embeddex:~/lab$ # file reports the type: empty
learner@embeddex:~/lab$ file notes/linux/lesson1.md
notes/linux/lesson1.md: empty
learner@embeddex:~/lab$ # redirect one line into it
learner@embeddex:~/lab$ echo hello > notes/linux/lesson1.md
learner@embeddex:~/lab$ # read it back
learner@embeddex:~/lab$ cat notes/linux/lesson1.md
hello
learner@embeddex:~/lab$ # -a reveals hidden dot files (. and ..)
learner@embeddex:~/lab$ ls -la notes/linux
total 12
drwxr-xr-x 2 learner learner 4096 Nov 15 05:32 .
drwxr-xr-x 3 learner learner 4096 Nov 15 05:32 ..
-rw-r--r-- 1 learner learner    6 Nov 15 05:32 lesson1.md
learner@embeddex:~/lab$ # an absolute path from the root /
learner@embeddex:~/lab$ head -n 5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
03

Environment, PATH, and working fast

5 min read

Your shell carries a set of s. printenv lists them all and env runs a command with a changed environment. The most important is .

bash
printenv PATH     # typical output: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

When you type a name that is not an alias, function or builtin, the shell walks $PATH in order and runs the first matching file. To see what a name really resolves to, use type; to see every match, use type -a; and to print just the path for use in a script, use command -v, which is the POSIX-standard form.

bash
type cd            # typical output: cd is a shell builtin
type -a echo       # typical output: echo is a shell builtin; echo is /usr/bin/echo; echo is /bin/echo
command -v python3 # typical output: /usr/bin/python3

The older which command only searches $PATH and therefore misses builtins and aliases entirely, which is why which echo prints only a path while type echo tells you the builtin runs. Use type to reason about the shell and command -v in scripts.

which vs type vs command -vwhichtypecommand -vSees aliasesnoyesyesSees builtinsnoyesyesShows allmatchesnowith -anoUse in scriptsavoidbash onlyyes, POSIXPrintsa pathwhat wouldrunpath or name
which, type and command -v answer subtly different questions

The shell remembers what you typed. history lists it, !n re-runs entry n, and !! re-runs the last command. The most useful habit, however, is reverse search: press Ctrl-R, start typing a fragment of an old command, and the shell shows the most recent match; press Ctrl-R again to cycle back. Tab completion is the other half of speed: type the first few letters of a command or path and press Tab to complete it, or press Tab twice to list the possibilities.

bash
history 5     # last five entries
!7            # re-run entry 7
!!            # re-run the previous command
Two habits that pay back daily

Install the habits, not the facts: press Tab instead of typing full paths, and press Ctrl-R instead of re-typing a long command. Ten minutes of deliberate practice today will save you an hour a week for the rest of the program.

Going deeperHow PATH lookup is really implemented

Bash keeps a hash table of commands it has already found, so a repeat command does not scan PATH again. That is why a newly installed program in a new directory is not found until the hash is refreshed, and why hash -r clears it. Bash also has a hook called command_not_found_handle that runs when a name resolves to nothing; on Ubuntu it is the source of the helpful suggestion that appears after a typo. This is the same machinery behind the exit status 127 you saw earlier.

Common mistakes and how to fix them

man cd prints No manual entry for cd. Cause: cd is a builtin, and builtins have no man page. Diagnose with type cd, then use help cd.

which echo shows only a path. Cause: which searches only PATH and misses builtins. Diagnose with type -a echo, which lists the builtin and the external programs.

ls -h seems to do nothing. Cause: -h only affects sizes, and only together with -l or -s. Fix: ls -lh.

apropos disk free finds nothing. Cause: apropos searches the manual's own words, not your paraphrase. Fix: try synonyms, such as apropos -a file system space, which returns df.

man write shows only the messaging command. Cause: the default section is 1. Diagnose with man -f write, then open section 2 with man 2 write.

You confuse exit statuses 2 and 127. Cause: 127 means the command was not found, while 2 means it ran but failed on its input. Diagnose by reading the message, and confirm with command; echo $?.

How PATH finds your commands
DLISR:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Microchip/xc8/v2.36/bin:/mnt/c/Program F
iles/Amazon/AWSCLIV2:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/GitHub CLI:/mnt/c/Program
Files/WSL:/mnt/c/Users/Eslam El Hefny/AppData/Local/hermes/bin:/mnt/c/Users/Eslam El Hefny/AppDa
ta/Local/Microsoft/WindowsApps:/mnt/c/Users/Eslam El Hefny/AppData/Local/Python/bin:/mnt/c/Users
/Eslam El Hefny/AppData/Local/Programs/MiKTeX/miktex/bin/x64:/mnt/c/Users/Eslam El Hefny/AppData
/Roaming/npm:/mnt/c/Users/Eslam El Hefny/AppData/Local/Microsoft/WinGet/Packages/BurntSushi.ripg
rep.MSVC_Microsoft.Winget.Source_8wekyb3d8bbwe/ripgrep-15.2.0-x86_64-pc-windows-msvc:/mnt/c/User
s/Eslam El Hefny/AppData/Local/Microsoft/WinGet/Packages/Gyan.FFmpeg_Microsoft.Winget.Source_8we
kyb3d8bbwe/ffmpeg-9.0-full_build/bin:/mnt/c/Users/Eslam El Hefny/AppData/Local/Programs/Cua/cua-
driver/bin:/mnt/c/Users/Eslam El Hefny/AppData/Local/Programs/cursor/resources/app/bin:/mnt/c/Us
ers/Eslam El Hefny/AppData/Local/Microsoft/WinGet/Packages/PHP.PHP.8.3_Microsoft.Winget.Source_8
wekyb3d8bbwe:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/Git/mingw64/bin:/mnt/c/Program Fil
es/GitHub CLI:/mnt/c/Program Files/Git/usr/bin/vendor_perl:/mnt/c/Program Files/Git/usr/bin/core
_perl
learner@embeddex:~/lab$ # type shows the first match bash would run
learner@embeddex:~/lab$ type python3
python3 is /usr/bin/python3
learner@embeddex:~/lab$ # command -v prints just the path, for scripts
learner@embeddex:~/lab$ command -v python3
/usr/bin/python3
learner@embeddex:~/lab$ # which only searches PATH, so it misses the builtin
learner@embeddex:~/lab$ which echo
/usr/bin/echo
04

Try it

1 min read

The lab for this lesson is a help-desk scavenger hunt: you answer three questions about how ls and cp behave, using only man, apropos and --help, and record the exact command that proves each answer. Then you build a small directory tree with absolute and relative paths and remove it, and you classify a list of commands as builtins or external programs with type. Before you start, re-read the two deep boxes on fork-exec-wait and on PATH lookup, and try the three habits yourself: type on a command you use every day, Tab on a path, and Ctrl-R on an old command.

Key takeaways

  • type tells you what a command really is; which only searches PATH and misses builtins and aliases.
  • For any command the help hierarchy is: help for builtins, --help for programs, man for the full reference, apropos when you forgot the name.
  • Tab completion and Ctrl-R are the two habits that make the shell feel fast; learn them on day one.

Reflect

  1. Explain to a colleague, in two sentences: find the answer to any how-do-I-use-X question with man, help, --help, apropos and type, recording the proof command.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?

On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

Practise this lessonExercises, quiz, interview preparation and spaced review

References and further reading

Official documentation first. Links checked when the lesson was published.

Find your next step

↑ ↓ to move · Enter to open · Esc to close