The shell: commands, paths and help

Commands, options, paths and getting help.

Beginner12 min · lesson 2 of 29

The previous lesson showed that the shell is the program that reads what you type. This one covers how to talk to it: how a command line is put together, how to move around the filesystem with absolute and relative paths, and how to get help from the server itself when you do not remember an option. With those three skills you can work out an unfamiliar command instead of memorising it, which is how experienced administrators actually work.

A command, its options and its arguments

When the prompt appears, you type a command line and press Enter. The first word is the command, the program to run. Words that start with a dash are options, which change how the command behaves. The remaining words are arguments, usually the files or directories to act on. Here the same command gets the same argument, once without and once with an option.

deploy@web01 · Ubuntu 26.04 LTS
$ ls /etc/hostname
/etc/hostname
$ ls -l /etc/hostname
-rw-r--r-- 1 root root 6 Sep 27 01:31 /etc/hostname

Without options, ls just confirms the name. The -l option asks for the long format: the file type and permissions, the number of links, the owner and group, the size in bytes, the time of the last change and the name. The lesson on permissions reads those columns one by one; for now it is enough to know where the size and the owner are.

Most options have two spellings: a short form, one dash and one letter, and a long form, two dashes and a word. Short options can be combined, so ls -la is the same as ls -l -a. Some options take a value, written after the short form or after an equals sign in the long form. Both of these print the first two lines of a file:

deploy@web01 · Ubuntu 26.04 LTS
$ head -n 2 /etc/os-release
PRETTY_NAME="Ubuntu 26.04.1 LTS" NAME="Ubuntu"
$ head --lines=2 /etc/os-release
PRETTY_NAME="Ubuntu 26.04.1 LTS" NAME="Ubuntu"

Scripts often use the long forms because they explain themselves; at the prompt the short forms save typing. A mistyped option makes the command stop before it does anything:

deploy@web01 · Ubuntu 26.04 LTS
$ ls --al
error: unexpected argument '--al' found tip: a similar argument exists: '--all' Usage: ls [OPTION]... [FILE]... For more information, try '--help'.

The message names the option it did not understand and suggests a real one. A long option may be shortened as long as the short form still fits only one option, so --almost-a works for --almost-all. --al fits both --all and --almost-all, and the tool refuses rather than guess. That wording comes from the Rust ls on Ubuntu 26.04; the GNU version (on RHEL, and as gnuls on Ubuntu) says the same thing differently:

deploy@web01 · Ubuntu 26.04 LTS
$ gnuls --al
gnuls: option '--al' is ambiguous; possibilities: '--all' '--almost-all' Try 'gnuls --help' for more information.

Two rules catch newcomers. Everything is case-sensitive: ls is a command, LS is not, and /var/log and /Var/log are different paths. Spaces separate the words of a command line, so a file name that contains a space must be quoted, or the command receives two arguments; the lesson on quoting and wildcards covers the details.

Where you are: absolute and relative paths

Every file has a path: the directories you pass through to reach it, separated by /. The tree starts at / itself, the root directory. Your shell also has a current directory (the working directory) at every moment, and pwd prints it. Right after you log in, it is your home directory.

deploy@web01 · Ubuntu 26.04 LTS
$ pwd
/home/deploy

An absolute path starts with / and means the same thing wherever you are. cd (change directory) moves you. Each terminal below starts a fresh shell in the home directory, so commands that belong together are shown together, one per line, as you would type them.

deploy@web01 · Ubuntu 26.04 LTS
$ cd /var/log pwd
/var/log

A relative path does not start with /; the shell reads it from the current directory. Two names are special in every directory: . is the directory itself and .. is its parent, one level up. The tilde ~ stands for your home directory, and cd with no argument goes straight there. cd - returns to the directory you were in before and prints its name.

deploy@web01 · Ubuntu 26.04 LTS
$ cd /var cd log pwd
/var/log
$ cd /var/log cd ../lib pwd
/var/lib
$ cd /etc cd /var/log cd -
/etc
$ cd /var/log cd pwd
/home/deploy

The most common path mistake is a missing leading slash. From the home directory, var/log means /home/deploy/var/log, which does not exist:

deploy@web01 · Ubuntu 26.04 LTS
$ ls var/log
ls: cannot access 'var/log': No such file or directory
$ ls -ld /var/log
drwxrwxr-x 13 root syslog 4096 Sep 27 13:56 /var/log

The error repeats the path exactly as you typed it, and that is the clue: it says var/log, not /var/log. With the slash the path works from anywhere. The -d option makes ls describe the directory itself instead of listing what is inside it.

Hidden files and your home directory

A name that starts with a dot is hidden: plain ls skips it and -a (all) shows it. Programs use this for their settings files, so they do not clutter a listing. Look at your own home directory with both options together.

deploy@web01 · Ubuntu 26.04 LTS
$ ls -la ~
total 20 drwxr-x--- 2 deploy deploy 4096 Sep 27 13:57 . drwxr-xr-x 4 root root 4096 Sep 27 13:56 .. -rw-r--r-- 1 deploy deploy 220 Feb 13 2026 .bash_logout -rw-r--r-- 1 deploy deploy 3771 Feb 13 2026 .bashrc -rw-r--r-- 1 deploy deploy 807 Feb 13 2026 .profile

The first line, total, is the disk space the listed files use, counted in blocks of 1 KiB. . is the home directory itself and .. is /home. .profile is read when you log in and .bashrc by interactive shells, and both were copied from /etc/skel when the account was created; the lesson on environment variables explains what goes in each. More dotfiles appear as you work, such as .bash_history for the commands you typed and .ssh once you use SSH keys.

The line for . shows the home directory as drwxr-x---: only you and your own group can look inside it, and other ordinary users cannot. RHEL 10 closes it to the group as well (drwx------). The permissions lesson explains how to read these letters, and the accounts lesson where the setting comes from.

Help that is already on the server

Nobody remembers every option. Three sources of help are installed on the server and work without internet access, and they describe the exact version you are running, which a web search may not. The quickest is --help, which almost every command accepts.

deploy@web01 · Ubuntu 26.04 LTS
$ 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. …

In the usage line, square brackets mark something optional and ... means it may be repeated, so ls [OPTION]... [FILE]... takes any number of options and any number of files, including none. For more detail, the manual page:

deploy@web01 · Ubuntu 26.04 LTS
$ man ls
LS(1) General Commands Manual LS(1) NAME ls - List directory contents. Ignore files and directories starting with a '.' by default …

At a terminal, man shows the page in a pager: Space and the arrow keys move through it, / followed by a word searches forward, n jumps to the next match and q quits. LS(1) means section 1 of the manual, commands for users. The Rust ls has its own, shorter page; man gnuls opens the GNU one, which also documents details such as exit statuses.

The section matters when a name means two things. man -f lists every page with that name:

deploy@web01 · Ubuntu 26.04 LTS
$ man -f passwd
passwd (1) - change user password passwd (1ssl) - OpenSSL application commands passwd (5) - the password file
$ man 5 passwd
PASSWD(5) File Formats and Configuration PASSWD(5) NAME passwd - the password file DESCRIPTION /etc/passwd contains one line for each user account, with seven fields …

Section 1 has the passwd command that changes a password, section 5 describes file formats such as /etc/passwd, and section 8 holds administration commands. Plain man passwd opens the first match in the search order, the command, so ask for man 5 passwd when you want the file. When you do not know the name at all, apropos searches the one-line descriptions of every page:

deploy@web01 · Ubuntu 26.04 LTS
$ apropos "list block devices"
lsblk (8) - list block devices

One gap surprises everyone once. cd has no manual page, because it is not a program on disk: it is built into bash, and so are a few dozen other commands such as export, alias and help itself. For those, help prints bash's own text.

deploy@web01 · Ubuntu 26.04 LTS
$ man cd
No manual entry for cd
$ help cd
cd: cd [-L|[-P [-e]]] [-@] [dir] Change the shell working directory. …

Let the shell do the typing

The last habits cannot be shown in a transcript because they happen as you type. Press Tab after the first few letters of a command, file or directory and bash completes it when there is only one match; press Tab twice to list the matches when there are several. When Tab does nothing, there is no match, which often means the path you are typing is wrong. On Ubuntu the bash-completion package also completes many commands' options and arguments.

The Up and Down arrows step through the commands you typed before, and Ctrl-R searches them; the lesson on quoting, wildcards and history goes further. Ctrl-C abandons the line you are typing or stops the program running in the foreground. Ctrl-D on an empty line ends the shell, which logs you out of an SSH session.

Try this

From your home directory, reach /var/log using only a relative path (cd ../../var/log), check with pwd, and come back with cd -. Then find the manual for the SSH server's configuration file: man -f sshd_config shows that it lives in section 5, so open it with man 5 sshd_config, press /, type PasswordAuthentication and press Enter to jump to that setting. Finally, use apropos to find the command that lists block devices, and read its --help.

Takeaway

Read any command line as command, options and arguments, and check paths for the leading slash first. When you are unsure of an option, ask the server (--help, man, help for builtins) before the internet: the local page describes the version you are running.

Quick check
01In your home directory /home/deploy you type ls var/log and get "ls: cannot access 'var/log': No such file or directory", although /var/log exists. Why?
Incorrect — A permission problem says "Permission denied". This error says the path does not exist, and ls -ld /var/log works without sudo.
Incorrect — A trailing slash is optional for directories. The missing character is at the start of the path, not the end.
Correct — A relative path is resolved from the current directory, so ls looked for /home/deploy/var/log.
Incorrect — Variables are expanded only when written with a dollar sign, as in $var. Plain words are passed unchanged.
02You want the meaning of each field in /etc/passwd, but man passwd shows a page about a command that changes passwords. What is the best next step?
Correct — The same name exists in section 1 (the command) and section 5 (the file format), and man opened section 1 first.
Incorrect — --help describes the command's options. The format of the file is documented separately, in section 5 of the manual.
Incorrect — The page is already installed; man -f passwd lists it. man only opened a different page with the same name.
Incorrect — help only describes commands built into bash. passwd is neither a builtin nor a file bash reads.
03man ls works on your server, but man cd prints "No manual entry for cd". What explains the difference?
Incorrect — If manual pages were stripped, man ls would fail too. The ls page is installed.
Incorrect — cd is not an alias. Aliases are shortcuts you define; cd is part of the shell program itself.
Incorrect — Manual pages are readable by every user. Nothing about cd's documentation requires privileges.
Correct — cd changes the shell's own current directory, so it must run inside the shell rather than as a separate program.

Related