Nandishwar Singh

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

  1. Terminal, console and shell
  2. How a command is put together
  3. Read the error, then the exit code
  4. Built in or a program? type and which
  5. Manual pages: man
  6. Quick help: --help
  7. Help for builtins: help
  8. Finding the right command: apropos and whatis
  9. Examples first: tldr
  10. Two commands to practise with: date and echo
  11. Two more keys: clear and exit
  12. Common mistakes
  13. Practice
  14. Cheat sheet

Terminal, console and shell

These three words get mixed up all the time, so here's what each one means.

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/bash

Bash 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/tmux

sh 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

  1. Print the shell you're using.
  2. Is zsh listed in /etc/shells on your VM?
Answer
  1. echo $SHELL prints /bin/bash.
  2. No. Only the shells that are installed are listed, and Ubuntu server doesn't install Zsh. sudo apt install -y zsh would 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 .profile

Single-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:

$ LS
LS: command not found
$ echo Hello,    world
Hello, world
$ echo "Hello,    world"
Hello,    world

Try it

  1. List /etc/skel with long details but without hidden files.
  2. What does ls -a /etc/skel show that plain ls /etc/skel doesn't?
  3. Print two spaces with the three spaces kept.
Answer
  1. Every file in /etc/skel is hidden, so you only get the total:
$ ls -l /etc/skel
total 0
  1. The hidden files: .bash_logout, .bashrc and .profile, plus . (the folder itself) and .. (the folder above it).
  2. 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 directory

Every 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

  1. 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>
127

127 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 builtin

ls 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/ls

type -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/echo

echo 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

  1. Is type itself a builtin or a program?
  2. Where does the date program 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:

KeyDoes
Space or fNext page
bPrevious page
Arrow keysOne line at a time
/word then EnterSearch for "word"
n / NNext / previous match
g / GTop / bottom
qQuit

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:

SectionContains
1Commands anyone can run
5File formats, like /etc/passwd
8Admin 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

  1. Open man ls, search for human, and find the option that prints sizes like 1K and 234M.
  2. What does section 8 of the manual contain? Check with man man.
Answer
  1. Type /human and press Enter. It's -h, used together with -l: ls -lh.
  2. Search man man for 8. 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 cd

Bash 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

  1. Get help on the pwd builtin.
  2. Get help on mkdir. Is it a builtin?
Answer
  1. help pwd.
  2. type mkdir says mkdir is /usr/bin/mkdir, a program, so use man mkdir or mkdir --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 attributes

man -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 file

Try it

  1. Find a command that lists directory contents, without using the word ls.
  2. What does whatis cp say?
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-8build1

Install 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

  1. Print the date as 21/10/2026, with today's date.
  2. Print I am ubuntu on linux using whoami and hostname inside $(...).
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

Practice

  1. Find out whether echo, history and cat are 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
  1. Using only man ls (no internet), find the option that sorts by size, largest first, and use it on /etc with 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
...
  1. 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 usage

It's df, which you used in lesson 1. du shows how much space files and folders take, which lesson 25 covers.

  1. Show the long options ls --help lists 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 ...

  1. 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:50
  1. ls returns 2 for a missing file. Run ls on 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
2

It's 2. ls lists what it can but still reports that something failed.

Cheat sheet

CommandWhat it does
echo $SHELLYour shell
cat /etc/shellsInstalled shells
cmd -a -b, cmd -ab, cmd --longOptions, joined options, long options
"text"Keep spaces exactly as typed
echo $?Exit code of the last command (0 = worked)
cmd1; cmd2Run two commands in a row
type nameBuiltin, alias or program?
type -a nameEvery meaning of a name
which nameWhere a program lives
man nameManual page (q quits, / searches)
man 5 namePage from a given section
name --helpShort option summary
help nameHelp for a builtin
apropos "words", man -kFind a command by what it does
whatis nameOne-line description
tldr nameShort examples (install tealdeer)
date +%Y-%m-%dDate in a format you choose
$(cmd)Put a command's output into a line
clear, exitClear the screen, leave the shell