unix-foundations Lesson 3 15 min read

How Do I Find Help in the Unix Manual?

Man pages, command history, and tab completion — the tools that make the shell feel like home

Reading: Linux Text: Ch. 2, pp. 45–60; Appendix A

After this lesson, you will be able to:

  • Use man to read the manual page for any Unix command
  • Navigate man pages (scroll, search with /, quit with q)
  • Understand man page sections (1-8) and use man N command for specific sections
  • Use --help flag and info as alternative help sources
  • Search your command history with history, Ctrl+R, and !n

You’re Stuck. Now What?

You’re in the terminal, you know the command you need is chmod, but you can’t remember the flags. In CSCD 210, you would hover over a method in VS Code and read the tooltip, or open Javadoc in a browser. But there’s no tooltip here. No autocomplete popup. Just a blinking cursor.

Unix has had a solution for this since the 1970s: man pages (manual pages). They’re the built-in documentation system, available on every Unix machine, no internet required. And once you learn to read them, you’ll find they’re more reliable than most StackOverflow answers.


Reading the Manual (and Working Faster)

Four Types of Commands

Before we look up help, it helps to know that Unix has four types of commands:

  1. Executable programs — compiled binaries in /usr/bin, /bin, etc. (e.g., ls, cp, gcc)
  2. Shell builtins — commands built into bash itself (e.g., cd, echo, exit)
  3. Shell functions — mini scripts defined in your environment
  4. Aliases — custom shortcuts (e.g., ll for ls -la)

You can find out what type a command is with type:

type ls

Output: ls is aliased to 'ls --color=auto' — it’s an alias!

type cd

Output: cd is a shell builtin — built into bash.

type gcc

Output: gcc is /usr/bin/gcc — an executable program.

The which command finds executables in your PATH:

which gcc          # /usr/bin/gcc
which cd           # (no output — cd is a builtin, not in PATH)

Key Insight: which only finds external programs. type finds everything — builtins, aliases, functions, and executables. When you want to know “what IS this command?”, use type. When you want to know “where is the binary?”, use which.

Man Pages: The Built-In Manual

Every standard Unix command has a manual page. To read it:

man ls

You’re now in a pager — a scrollable document viewer. Navigate with:

Key Action
Arrow keys, j/k Scroll line by line
Space, Page Down Next page
b, Page Up Previous page
/pattern Search forward for “pattern”
n Jump to next search match
N Jump to previous search match
q Quit

Reading a Man Page

Every man page follows the same structure:

LS(1)                    User Commands                    LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List information about the FILEs (the current directory
       by default). Sort entries alphabetically...

OPTIONS
       -a, --all
              do not ignore entries starting with .
       -l     use a long listing format
       ...

EXAMPLES
       ...

SEE ALSO
       ...

The key sections:

  • NAME — what it does (one line)
  • SYNOPSIS — how to call it (brackets [] mean optional)
  • DESCRIPTION — detailed explanation
  • OPTIONS — all the flags and what they do
  • EXAMPLES — usage examples (not all man pages have these)
  • SEE ALSO — related commands

From Java: Javadoc is organized by class, with method signatures and descriptions. Man pages are organized by command, with synopses and option lists. The structure is different, but the skill is the same: reading technical reference documentation. Learning to read man pages is a professional skill that transfers everywhere.

Check Your Understanding
You want to know whether cd is a program installed on your system or something built into the shell. Which command tells you?
A which cd
B man cd
C type cd
D ls /usr/bin/cd
Answer: C. type identifies all four categories of commands: executables, builtins, functions, and aliases. which only finds executables in your PATH — it would produce no output for cd since it's a builtin. man cd might show documentation but doesn't tell you the command type. And cd doesn't live in /usr/bin because it's not a separate program.

Man Page Sections

The number in parentheses (like LS(1)) refers to the section:

Section Contents When You’ll Use It
1 User commands Most of the time
2 System calls Week 10 (fork, pipe)
3 C library functions Weeks 3–9 (printf, malloc)
5 File formats Config files
8 Admin commands Rarely

Why does this matter? Some names exist in multiple sections:

man printf           # Section 1: the shell command
man 3 printf         # Section 3: the C library function

You’ll use man 3 extensively when writing C code — it’s the reference for printf, scanf, malloc, fopen, and every other C library function.

Why does this matter?

Starting in Week 3, you’ll call C library functions like printf and malloc constantly. The man page for each function shows the exact header to #include, the parameter types, and the return value. Getting the section number right (section 3, not section 1) is the difference between finding the answer in 10 seconds and wandering through irrelevant documentation.

Check Your Understanding
You run man printf and get documentation for a shell command, but you wanted the C library function. What went wrong?
A The C library version of printf doesn't have a man page
B You need to use info printf instead of man
C You need to install the C library documentation separately
D You need to specify section 3: man 3 printf
Answer: D. printf exists in both section 1 (user commands) and section 3 (C library functions). Without a section number, man returns the first match it finds — usually section 1. Specifying man 3 printf goes straight to the C library version with the function signature, required headers, and return value.

Searching for Commands

Don’t know the command name? Search by keyword:

man -k permission     # Find commands related to "permission"

This might show:

chmod (1)            - change file mode bits
chown (1)            - change file owner and group
stat (1)             - display file status

apropos does the same thing:

apropos directory     # Find commands related to "directory"

Quick Help: --help

Most commands support a --help flag for a brief usage summary:

ls --help

This is faster than man when you just need a quick reminder of a flag.

Command History: Stop Retyping

Every command you type is saved in your history. This is a massive time-saver:

history              # Show all previous commands (numbered)

Navigation shortcuts:

Key/Command Action
Up arrow Previous command
Down arrow Next command
!! Re-run the last command
!n Re-run command number n from history
!ls Re-run most recent command starting with ls
Ctrl+R Reverse search — type part of a command, see matches

The Trick: Ctrl+R is the single most useful history shortcut. Press Ctrl+R, start typing part of a previous command, and it shows the most recent match. Press Ctrl+R again to cycle through older matches. Press Enter to run it, or arrow keys to edit it first.

Example workflow:

gcc -Wall -o myprogram myprogram.c     # Compile (long command)
./myprogram                             # Run
# Find a bug, edit the file...
Ctrl+R then type "gcc"                  # Instantly recalls the compile command

Tab Completion: Let the Shell Do the Typing

Press Tab to auto-complete file names, directory names, and command names:

cd ~/csc<Tab>          # Completes to cd ~/cscd240/
ls my<Tab>             # Completes to ls myprogram.c

If there are multiple matches, press Tab twice to see all possibilities:

ls my<Tab><Tab>
# myprogram.c  myprogram.h  myfile.txt

The Trick: If Tab doesn’t complete anything, either: (1) no file matches what you’ve typed (check for typos), or (2) the file doesn’t exist. Tab completion doubles as a quick existence check.

Essential Keyboard Shortcuts

These work in any bash session:

Shortcut Action
Ctrl+C Cancel current command (essential!)
Ctrl+D Send EOF / close shell
Ctrl+A Jump to beginning of line
Ctrl+E Jump to end of line
Ctrl+K Delete from cursor to end of line
Ctrl+U Delete from cursor to beginning of line
Ctrl+L Clear screen (same as clear command)

Common Pitfall: Ctrl+C and Ctrl+D do different things. Ctrl+C cancels whatever is currently running — use it when a program hangs or you want to abort. Ctrl+D sends an end-of-file signal — if the line is empty, it closes your terminal. Don’t confuse them.

Check Your Understanding
Your C program is stuck in an infinite loop and won't stop printing output. What should you press?
A Ctrl+D to close the program
B Ctrl+Z to end the process
C Ctrl+C to cancel the running command
D Close the terminal window and open a new one
Answer: C. Ctrl+C sends an interrupt signal that terminates the running process. Ctrl+D sends an EOF signal, which doesn't help with a runaway program — it's for telling a program you're done providing input. Ctrl+Z suspends the process (it's still alive in the background, not killed). Closing the terminal works but is overkill — you lose your entire session.

The echo Command

echo prints text to the screen. Simple, but useful:

echo "Hello, world!"           # Print a message
echo $HOME                      # Print the value of HOME variable
echo $?                         # Print exit status of last command

The exit status ($?) is important: 0 means success, any other number means error. You’ll use this in scripts and when debugging.

Quick Check: How do you look up the C library version of printf instead of the shell command?

Use man 3 printf. The 3 specifies section 3 (C library functions) instead of section 1 (user commands).

Quick Check: What's the fastest way to re-run a command you typed 20 commands ago?

Use Ctrl+R and start typing part of the command. Or use history to find its number, then !n to re-run it. Ctrl+R is usually faster because you don’t need to look up the number.

Quick Check: You type cd cscd and press Tab, but nothing happens. Why?

Either there’s no directory starting with cscd in the current location (check with ls), or there are multiple matches (press Tab twice to see them). Tab completion also confirms that a file or directory exists.


You’re No Longer Lost

You now have three superpowers: man for looking up any command, history and Ctrl+R for recalling previous commands, and Tab for auto-completing paths. These aren’t just nice-to-have — they’re how experienced Unix users work so fast. They’re not memorizing hundreds of flags; they’re looking them up efficiently.

Next up: file permissions. You’ve been creating and moving files, but who else can see them? And what does that rwxr-xr-x string mean in the ls -l output? That’s Lesson 1.4.

Big Picture: Man pages are your primary reference for C library functions. When you start writing C code in Week 3, man 3 printf and man 3 scanf will be commands you type multiple times per lab session. The skill you’re building now — reading technical documentation — is the same skill professional developers use every day.