Home / Learn Linux / Lesson 2
The shell, commands and getting help
How a command is put together, and how to find out what any command does with man, help and --help.
- Lesson
- 2 of 30
- Time
- About 40 minutes
On this page
- Terminal, console and shell
- How a command is put together
- Read the error, then the exit code
- Built in or a program? type and which
- Manual pages: man
- Quick help: --help
- Help for builtins: help
- Finding the right command: apropos and whatis
- Examples first: tldr
- Two commands to practise with: date and echo
- Two more keys: clear and exit
- Common mistakes
- Practice
- Cheat sheet
Terminal, console and shell
These three words get mixed up all the time, so here's what each one means.
- The terminal is the window you type in: Terminal on a Mac, Windows Terminal, the terminal app on Pop!_OS. On its own it does nothing except show text and pass your keys along.
- A console is a terminal that's built into the machine itself, like the black login screen a server shows when you plug in a monitor. Linux calls these text screens TTYs.
- The shell is the program that actually reads what you type, runs it and prints the result. On Ubuntu it's called Bash.
When you run multipass shell linux, your terminal connects to a Bash shell inside the VM. Ask it which shell you're in:
$ echo $SHELL
/bin/bashBash isn't the only shell. /etc/shells lists the ones installed on this machine:
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/usr/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/usr/bin/dash
/usr/bin/screen
/usr/bin/tmuxsh and dash are small, fast shells that scripts often use. Zsh and fish are popular on desktops (macOS uses Zsh). Everything in this course uses Bash, the default on almost every Linux server.
The prompt ends in $ when you're a normal user and # when you're root, the administrator. Lesson 3 covers root. For now, if you see #, slow down.
Try it
- Print the shell you're using.
- Is
zshlisted in/etc/shellson your VM?
Answer
echo $SHELLprints/bin/bash.- No. Only the shells that are installed are listed, and Ubuntu server doesn't install Zsh.
sudo apt install -y zshwould add it.
How a command is put together
Every command has the same shape: the command, then options that change how it behaves, then arguments that tell it what to work on.
ls -l -a /etc/skel │ └─┬─┘ └───┬───┘ │ options argument command
ls lists files. -l asks for the long format with details, -a asks for all files including hidden ones (names starting with a dot), and /etc/skel is the folder to list. It's the folder whose files get copied into every new user's home folder.
$ ls -l -a /etc/skel
total 20
drwxr-xr-x 2 root root 4096 Jul 20 16:33 .
drwxr-xr-x 107 root root 4096 Oct 21 10:50 ..
-rw-r--r-- 1 root root 220 Feb 13 2026 .bash_logout
-rw-r--r-- 1 root root 3771 Feb 13 2026 .bashrc
-rw-r--r-- 1 root root 807 Feb 13 2026 .profileSingle-letter options can be joined, and most have a long version with two dashes that's easier to read in scripts. These all do the same thing:
$ ls -l -a /etc/skel $ ls -la /etc/skel $ ls -al /etc/skel $ ls --all -l /etc/skel
A few rules hold for every command:
- Upper and lower case are different.
lsandLSare two different names, and only one of them exists:
$ LS
LS: command not found- Spaces separate arguments. The shell splits what you type on spaces, so extra spaces vanish. Quotes keep text together exactly as written:
$ echo Hello, world Hello, world $ echo "Hello, world" Hello, world
- Options usually come before arguments. Many commands accept them in any order, but options first always works.
Try it
- List
/etc/skelwith long details but without hidden files. - What does
ls -a /etc/skelshow that plainls /etc/skeldoesn't? - Print
two spaceswith the three spaces kept.
Answer
- Every file in
/etc/skelis hidden, so you only get the total:
$ ls -l /etc/skel
total 0- The hidden files:
.bash_logout,.bashrcand.profile, plus.(the folder itself) and..(the folder above it). echo "two spaces". Without the quotes you get one space.
Read the error, then the exit code
When something goes wrong, Linux tells you. Errors almost always follow the pattern program: what it was doing: what went wrong:
$ ls /nope
ls: cannot access '/nope': No such file or directoryEvery command also returns an exit code when it finishes: 0 means it worked, anything else means it didn't. The shell keeps the last one in $?:
$ ls /nope; echo $? ls: cannot access '/nope': No such file or directory 2 $ ls /etc/skel; echo $? 0
The ; runs one command after the other on the same line. You won't check $? by hand often, but scripts do it all the time (lesson 28), so it's worth knowing it's there.
Try it
- Run a command that doesn't exist, like
foo, then check its exit code.
Answer
$ foo; echo $?
Command 'foo' not found, did you mean:
command 'fop' from deb fop (1:2.10+dfsg-2)
command 'foot' from deb foot (1.25.0-1)
command 'fox' from deb objcryst-fox (2022.1-2build1)
command 'goo' from deb goo (0.155+ds-6build1)
command 'fio' from deb fio (3.41-2)
Try: sudo apt install <deb name>
127127 is the shell's code for "command not found". ls used 2 for a missing file. Each program chooses its own non-zero codes, but 0 always means success.
Built in or a program? type and which
Some commands are separate programs stored on disk. Others are built into Bash itself, and some are aliases, nicknames that expand into a longer command. type tells you which is which:
$ type ls cd pwd
ls is aliased to `ls --color=auto'
cd is a shell builtin
pwd is a shell builtinls is an alias: Ubuntu's .bashrc makes ls mean ls --color=auto, which is why folders show up in color. cd and pwd are shell builtins. cd has to be one, because only the shell itself can change the folder it's working in.
which prints where a program lives on disk:
$ which ls
/usr/bin/lstype -a lists everything a name could mean, in the order Bash checks them:
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echoecho is a builtin and also a program in /usr/bin. When you type echo, the builtin wins. This matters for the next part, because builtins and programs get their help in different places.
Try it
- Is
typeitself a builtin or a program? - Where does the
dateprogram live?
Answer
$ type type type is a shell builtin $ which date /usr/bin/date
Manual pages: man
Almost every program comes with a manual page. man opens it:
$ man ls
LS(1) General Commands Manual LS(1)
NAME
ls - List directory contents. Ignore files and directories
starting with a '.' by default
SYNOPSIS
ls [--help] [--format] [-C ] [-l|--long] [-x ] [-T|--tabsize]
[-m ] [--zero] [-D|--dired] [--hyperlink] [-1 ] [-o ] [-g ]
[-n|--numeric-uid-gid] [--quoting-style] [-N|--literal]
[-b|--escape] [-Q|--quote-name] [-q|--hide-control-chars]
[--show-control-chars] [--time] [-c ] [-u ] [--hide] [-I|--ig‐
nore] [-B|--ignore-backups] [--sort] [-S ] [-t ] [-v ] [-X ] [-U
] [-L|--dereference] [--dereference-command-line-symlink-to-dir]
...The page opens in a pager, so you can move around in it:
| Key | Does |
|---|---|
Space or f | Next page |
b | Previous page |
| Arrow keys | One line at a time |
/word then Enter | Search for "word" |
n / N | Next / previous match |
g / G | Top / bottom |
q | Quit |
Every man page has the same parts. NAME says what it does in one line. SYNOPSIS shows the shape of the command, where anything in [ ] is optional and ... means "one or more". DESCRIPTION explains every option. Many pages end with EXAMPLES and SEE ALSO, which are worth jumping to with G.
On Ubuntu 26.04, ls is the new Rust version, so man ls is shorter than the classic GNU page you'll find online. The options you'll use every day are the same.
Sections
Man pages are grouped into numbered sections. The ones you'll meet:
| Section | Contains |
|---|---|
| 1 | Commands anyone can run |
| 5 | File formats, like /etc/passwd |
| 8 | Admin commands, usually run as root |
When a name exists in more than one section, put the number first. passwd is both a command (change your password) and a file (the list of users):
$ man 5 passwd
PASSWD(5) File Formats and Configuration PASSWD(5)
NAME
passwd - the password file
...Try it
- Open
man ls, search forhuman, and find the option that prints sizes like1Kand234M. - What does section 8 of the manual contain? Check with
man man.
Answer
- Type
/humanand press Enter. It's-h, used together with-l:ls -lh. - Search
man manfor8. Section 8 is "System administration commands (usually only for root)".
Quick help: --help
Most programs print a short summary of their options with --help. It's faster than the man page when you only need to remember a flag:
$ ls --help
List directory contents.
Ignore files and directories starting with a '.' by default
Usage: ls [OPTION]... [FILE]...
Options:
--help
Print help information.
--format <format>
Set the display format.
...Long help output scrolls off the screen. Lesson 8 shows how to page through it with | less.
Help for builtins: help
Builtins don't have their own man pages:
$ man cd
No manual entry for cdBash has its own help command for them:
$ help cd
cd: cd [-L|[-P [-e]]] [-@] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable. If DIR is "-", it is converted to $OLDPWD.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
...So when you need help, ask type first: a builtin uses help name, and a program uses man name or name --help.
Try it
- Get help on the
pwdbuiltin. - Get help on
mkdir. Is it a builtin?
Answer
help pwd.type mkdirsaysmkdir is /usr/bin/mkdir, a program, so useman mkdirormkdir --help.
Finding the right command: apropos and whatis
Sometimes you know what you want to do but not which command does it. apropos searches the one-line descriptions of every man page:
$ apropos copy
aarch64-linux-gnu-objcopy (1) - copy and translate object files
bcopy (3) - copy byte sequence
btrfs-select-super (8) - overwrite primary superblock with a backup copy
copy_file_range (2) - Copy a range of data from one file to another
copysign (3) - copy sign of a number
copysignf (3) - copy sign of a number
copysignl (3) - copy sign of a number
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
dd (1) - Copy, and optionally convert, a file system re...
...That's a lot of noise. Search for a phrase in quotes to narrow it down:
$ apropos "copy files"
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
git-checkout-index (1) - Copy files from the index to the working tree
gnucp (1) - copy files and directories
gnuinstall (1) - copy files and set attributesman -k does exactly the same thing. whatis goes the other way: give it a name and it prints the one-line description from each section:
$ whatis passwd
passwd (1) - change user password
passwd (1ssl) - OpenSSL application commands
passwd (5) - the password fileTry it
- Find a command that lists directory contents, without using the word
ls. - What does
whatis cpsay?
Answer
$ apropos "directory contents" dir (1) - List directory contents. Ignore files and dire... gnudir (1) - list directory contents gnuls (1) - list directory contents gnuvdir (1) - list directory contents ls (1) - List directory contents. Ignore files and dire... ntfsls (8) - list directory contents on an NTFS filesystem rust-dir (1) - List directory contents. Ignore files and dire... rust-ls (1) - List directory contents. Ignore files and dire... rust-vdir (1) - List directory contents. Ignore files and dire... vdir (1) - List directory contents. Ignore files and dire... $ whatis cp cp (1) - copy files and directories
dir and vdir are older cousins of ls. The rust- and gnu names are Ubuntu 26.04 keeping both versions side by side: ls is the Rust one, and gnuls is the classic GNU ls if you ever need it.
Examples first: tldr
Man pages are complete but long. tldr shows a handful of real examples for a command instead. It isn't installed by default, and if you try it, Ubuntu tells you how to get it:
$ tldr
Command 'tldr' not found, but can be installed with:
sudo apt install tealdeer # version 1.8.1-1, or
sudo apt install tldr-py # version 0.7.0-8build1Install tealdeer, download the example pages once, then ask:
$ sudo apt install -y tealdeer Installing: tealdeer ... $ tldr --update Successfully updated cache. ... $ tldr tar Archiving utility. Often combined with a compression method, such as `gzip` or `bzip2`. More information: <https://www.gnu.org/software/tar/manual/tar.html>. [c]reate an archive and write it to a [f]ile: tar cf path/to/target.tar path/to/file1 path/to/file2 ... [c]reate a g[z]ipped archive and write it to a [f]ile: tar czf path/to/target.tar.gz path/to/file1 path/to/file2 ... [c]reate a g[z]ipped (compressed) archive from a directory using relative paths: tar czf path/to/target.tar.gz [-C|--directory] path/to/directory . ...
Use tldr to get going quickly and man when you need the exact details.
Two commands to practise with: date and echo
date prints the date and time, and you can choose the format with + followed by placeholders:
$ date Wed Oct 21 10:50:41 UTC 2026 $ date +%Y-%m-%d 2026-10-21 $ date "+%A, %d %B %Y, %H:%M" Wednesday, 21 October 2026, 10:50
%Y is the year, %m the month, %d the day, %H:%M hours and minutes, %A the weekday and %B the month name. man date lists them all. You'll use date +%Y-%m-%d constantly to name backup files.
echo prints whatever you give it. It's how scripts talk to you:
$ echo "Today is $(date +%A)"
Today is Wednesday$(...) runs a command and drops its output into the line. Lesson 28 uses it a lot.
The VM's clock is in UTC, the timezone servers almost always use, so the time may not match your watch.
Try it
- Print the date as
21/10/2026, with today's date. - Print
I am ubuntu on linuxusingwhoamiandhostnameinside$(...).
Answer
$ date +%d/%m/%Y 21/10/2026 $ echo "I am $(whoami) on $(hostname)" I am ubuntu on linux
Two more keys: clear and exit
clear wipes the screen (Ctrl+L does the same). exit closes the shell. In a Multipass shell, that takes you back to your own computer.
Common mistakes
- Wrong case.
Ls,LSandlsare different names. Commands are almost always lowercase. - No space between a command and its options.
ls-lis one word, so the shell looks for a program calledls-l. It'sls -l. - One dash on a long option.
ls -alldoesn't mean--all. It means-a -l -l, which happens to work here, but on other commands the result can surprise you. Long options always take two dashes. - Looking for the man page of a builtin.
man cdfinds nothing. Check withtype, then usehelp cd. - Getting stuck in a pager. If the screen is full of text and nothing you type seems to work, you're in a pager. Press
q.
Practice
- Find out whether
echo,historyandcatare builtins, programs or aliases, all in one command.
Answer
$ type echo history cat
echo is a shell builtin
history is a shell builtin
cat is /usr/bin/cat- Using only
man ls(no internet), find the option that sorts by size, largest first, and use it on/etcwith long details.
Answer
Search for size inside man ls. It's -S:
$ ls -lS /etc
total 920
-rw-r--r-- 1 root root 78419 Oct 14 2025 mime.types
-rw-r--r-- 1 root root 22623 Oct 21 08:30 ld.so.cache
-rw-r--r-- 1 root root 12990 Mar 15 2025 services
drwxr-xr-x 9 root root 12288 Oct 21 08:30 apparmor.d
...- Find a command that reports how much space file systems are using, without already knowing its name.
Answer
$ apropos "space usage"
df (1) - report file system space usage
du (1) - Estimate file space usage
gnudf (1) - report file system space usage
gnudu (1) - estimate file space usage
rust-du (1) - Estimate file space usageIt's df, which you used in lesson 1. du shows how much space files and folders take, which lesson 25 covers.
- Show the long options
ls --helplists for showing hidden files.
Answer
ls --help shows -a, --all for every file including . and .., and -A, --almost-all for every hidden file but without . and ...
- Print a line like
Backup started 2026-10-21 at 10:47, using today's date and time.
Answer
$ echo "Backup started $(date +%Y-%m-%d) at $(date +%H:%M)"
Backup started 2026-10-21 at 10:50lsreturns 2 for a missing file. Runlson one folder that exists and one that doesn't, in a single command, then check the exit code. Is it 0 or 2?
Answer
$ ls /etc/apt /nope; echo $?
ls: cannot access '/nope': No such file or directory
/etc/apt:
apt.conf.d keyrings sources.list trusted.gpg.d
auth.conf.d preferences.d sources.list.d
2It's 2. ls lists what it can but still reports that something failed.
Cheat sheet
| Command | What it does |
|---|---|
echo $SHELL | Your shell |
cat /etc/shells | Installed shells |
cmd -a -b, cmd -ab, cmd --long | Options, joined options, long options |
"text" | Keep spaces exactly as typed |
echo $? | Exit code of the last command (0 = worked) |
cmd1; cmd2 | Run two commands in a row |
type name | Builtin, alias or program? |
type -a name | Every meaning of a name |
which name | Where a program lives |
man name | Manual page (q quits, / searches) |
man 5 name | Page from a given section |
name --help | Short option summary |
help name | Help for a builtin |
apropos "words", man -k | Find a command by what it does |
whatis name | One-line description |
tldr name | Short examples (install tealdeer) |
date +%Y-%m-%d | Date in a format you choose |
$(cmd) | Put a command's output into a line |
clear, exit | Clear the screen, leave the shell |
← What Linux is and how to get itTerminal speed: Tab, shortcuts, history and sudo →