Find a course

Module 1: Getting Started in the TerminalLesson 2 of 1310 min

Anatomy of a Command and Getting Help

Break any command into name, options and arguments, look up what it does with man and --help, and save time with tab completion and history.

Step 1 of 12Learn

A command is a short sentence

Almost every command you will type follows the same grammar:

command  -options  arguments

Take ls -l /etc:

  • ls is the command, the program to run (list directory contents).
  • -l is an option (also called a flag). It changes how the command behaves, here asking for a long, detailed listing.
  • /etc is an argument. It tells the command what to act on, here the /etc directory.

Options come in two styles. Short options are a single dash and a single letter: -l, -a, -h. Several short options can usually be combined, so ls -l -a -h and ls -lah mean the same thing. Long options use two dashes and a whole word: --all, --human-readable. They are easier to read in scripts.

Spaces matter. The shell splits your line on spaces, so ls -l/etc is not the same as ls -l /etc. If a file name contains a space, wrap it in quotes: ls "My Documents". Otherwise the shell sees two separate arguments, My and Documents.

Linux is also case-sensitive. ls works; LS gives "command not found". Report.txt and report.txt are two different files.

Step 2 of 12Practice · Diagram

The grammar of ls -l /etc

Which part tells the command what to act on?

Tap the shape that answers the question, then press Check.

The grammar of ls -l /etcParts diagram: ls -l /etc, ls: the command, -l: an option, /etc: an argument.ls -l /etcls: thecommand-l: an option/etc: anargument
ls -l /etc
ls: the command

The program to run: list directory contents.

-l: an option

Changes how the command behaves: a long, detailed listing.

/etc: an argument

Says what to act on: the /etc directory.

Step 3 of 12Practice · Sort into groups

In the command grep -i --count error app.log server.log, sort each part.

Tap an item, then tap its group (or drag it there).

Step 4 of 12Learn

Getting help without leaving the terminal

Nobody memorizes every option. Experienced admins look things up constantly, and Linux ships with its documentation built in.

  • man ls opens the manual page for ls. Man pages have standard sections: NAME, SYNOPSIS (the grammar), DESCRIPTION and a list of options. Scroll with the arrow keys or Space, search by typing / followed by a word, and press q to quit.
  • ls --help prints a shorter summary straight to the screen. Most modern commands support it.
  • type cd tells you whether a name is a program on disk, a shell built-in, or an alias. Built-ins like cd are documented with help cd in Bash.
  • apropos copy (or man -k copy) searches man page descriptions when you know what you want to do but not the command name.

The SYNOPSIS line uses a small notation worth knowing: square brackets mark something optional and ... means "one or more". So cp [OPTION]... SOURCE DEST says options are optional, while a source and destination are required.

A realistic workflow: you need to show file sizes in a friendly format. You run man ls, type /human, press Enter and find -h, --human-readable. Thirty seconds, no web search.

Step 5 of 12Diagram

Thirty seconds in a man page

The workflow from the text: find the option for human-friendly sizes without leaving the terminal.

Thirty seconds in a man pageProcess diagram: man ls → Type /human → Press Enter → Find -h, --human-readable → Press q.man lsType /humanPress EnterFind -h,--human-readablePress q

Tap a shape with to see more.

man ls

Opens the manual page for ls.

Type /human

/ starts a search inside the page.

Press Enter

Jumps to the first match. Press n for the next one.

Find -h, --human-readable

Now you know ls -lh shows sizes like 4.0K and 20M.

Press q

Quits the page and returns to the prompt.

Step 6 of 12Practice · Match the pairs

Match each help tool to the situation it fits best.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. man tar
  2. tar --help
  3. apropos compress
  4. type cd

Step 7 of 12Learn

Tab completion and history

Two keyboard habits make the command line much faster and safer.

Tab completion. Type the first few letters of a command, file or directory and press Tab. If there is one match, the shell fills in the rest. If there are several, press Tab twice to see them all. Typing cd /usr/sh and pressing Tab becomes cd /usr/share/. Completion prevents typos in long file names, and if Tab completes nothing, that is an early warning that the path you are typing doesn't exist.

History. The shell remembers what you have typed.

  • Up arrow steps back through previous commands; edit one and press Enter to run it again.
  • history lists recent commands with numbers.
  • Ctrl+R starts a reverse search: type part of an old command and Bash finds the most recent match. Press Ctrl+R again to go further back.
  • !! repeats the last command. A classic use is sudo !! after forgetting to use sudo.

A few more keys worth knowing: Ctrl+C cancels the command that is running, Ctrl+L clears the screen (same as clear), Ctrl+A and Ctrl+E jump to the start and end of the line, and Ctrl+D on an empty line closes the shell.

Step 8 of 12Note

Step 9 of 12Flashcards

Keyboard shortcuts

Tap a card to flip it.

Step 10 of 12Practice · Spot the mistake

A new team member wrote these notes about commands. Tap the two lines that are wrong.

Step 11 of 12Practice · True or false

Pressing Tab twice when there are several possible completions shows you the list of matches.

Step 12 of 12Practice · Choose one

You want to know which option of df shows sizes like "20G" instead of raw block counts, but you are on a server with no internet access. What is the best first move?