Courseiva
LPIC-1Chapter 3 of 17Objective 103.1

Command Line Basics and Shell Fundamentals

The LPIC-1 exam objective 103.1 — Work on the command line — is the single most fundamental skill you will learn. This concept, 'Command Line Basics and Shell Fundamentals', solves the problem of how to talk directly to your computer's operating system without clicking a mouse or poking a touchscreen. It matters because every IT professional from a junior sysadmin to a cloud architect uses the command line as their primary tool to configure servers, diagnose problems, and automate tasks; if you cannot navigate this environment, you cannot pass the exam or do the job.

12 min read
Beginner
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security · IEEE Senior Member

A simple way to picture Command Line Basics and Shell Fundamentals

The Master Chef's Kitchen Analogy

The Head Chef orchestrating a professional kitchen. You are not just cooking; you are commanding an entire culinary operation. The head chef sits at the central pass, not touching the food directly, but issuing precise orders to the line cooks, sauciers, and pastry chefs. This is your shell environment.

Each command you type is an order. 'ls' is like calling out 'Show me what's prepped on the counter!' — it lists all the ingredients (files and directories) in your current station (working directory). 'cd' is the order to move to a different station, like the grill section or the walk-in cooler, changing your context. 'cat' is asking a commis to hand you a specific recipe card and read it out loud.

The command line prompt — the blinking cursor with a '$' or '#' — is the chef's notepad, waiting for the next instruction. Options like '-l' or '-a' are like specifying 'give me the full ingredient list with weights' or 'show me even the hidden prep notes'. The shell itself is the kitchen's communication system — the headset and the call station — that interprets your spoken orders (commands) and directs the kitchen brigade (the Linux operating system) to execute them. Without this structured command language, the kitchen would collapse into chaotic shouting; with it, a complex feast can be orchestrated seamlessly. Every master chef started with learning this precise language of orders.

How It Actually Works

The command line is a text-based interface to your computer's operating system. Instead of using windows, icons, and a mouse (a GUI or 'graphical user interface'), you type commands and the computer responds with text. The 'shell' is the program that interprets these commands. The most common shell on Linux is called 'Bash' (Bourne Again SHell). When you open a terminal window, you are launching a shell, which presents you with a 'prompt' — usually ending with a dollar sign ($) for a normal user or a hash (#) for the root (superuser). This prompt is waiting for your input.

Here is how a basic command works: you type the command name, optionally followed by 'options' (also called flags) and 'arguments', then press Enter. For example, the command 'ls -l /home' breaks down as follows.

'ls' is the command itself, short for 'list'.

'-l' is an option (or flag) that modifies how the command behaves, in this case telling it to use 'long format' showing file permissions, sizes, and dates.

'/home' is an argument, specifying which directory to list.

Options can often be combined. For instance, 'ls -la' combines the '-l' (long) and '-a' (all, including hidden files) options. Arguments tell the command what to act upon. Many commands accept multiple arguments. The structure is always: command [options] [arguments].

Why does this exist? Before graphical interfaces, this was the only way to interact with computers. The command line remains incredibly powerful because it is scriptable — you can write multiple commands in a text file (a 'shell script') and execute them all at once, automating repetitive tasks. It is also lightweight and efficient; you can manage thousands of servers remotely over a slow network connection, something a GUI would struggle with.

Key environment variables control how your shell behaves. The 'PATH' variable is crucial: it is a list of directories (folders) that your shell searches through to find the commands you type. When you type 'ls', the shell looks in each directory listed in PATH (like /bin, /usr/bin) until it finds an executable file called 'ls'. You can see your PATH by typing 'echo $PATH'. The dollar sign ($) tells the shell to get the value of the variable. 'HOME' is another important variable, pointing to your personal user directory (e.g., /home/john). 'USER' holds your username.

The shell also keeps a history of commands you have typed. You can press the Up Arrow key to recall previous commands, or type 'history' to see a numbered list. You can re-run a command by typing '!n' where n is the history number. This saves huge amounts of time.

Tab completion is your best friend. If you start typing a command or filename and press Tab, the shell will automatically complete it for you, or show you options if there is ambiguity. This prevents typos and speeds you up enormously.

Finally, there are two types of commands: internal (built-in to the shell, like 'cd' and 'echo') and external (separate programs, like 'ls' and 'cp'). You can use the 'type' command to check which is which (e.g., 'type cd' returns 'cd is a shell builtin'). This distinction matters because built-ins do not fork a new process, making them slightly faster.

Flowchart showing how a user's typed command is processed by the shell, including the distinction between built-in and external commands.

Walk-Through

1

Opening the Terminal

You launch a terminal emulator program (like GNOME Terminal or Konsole). This opens a blank window that represents the shell. You are now presented with a prompt, such as 'john@laptop:~$'. The structure is 'username@hostname:current_directory$'. The tilde (~) means you are in your home directory.

2

Typing Your First Command: pwd

You type 'pwd' (print working directory) and press Enter. The shell finds the 'pwd' executable in a directory listed in the PATH variable, runs it, and prints the full path to your current directory, e.g., '/home/john'. This confirms where you are in the filesystem.

3

Navigating with cd

You type 'cd /tmp' to change to the /tmp directory. The shell's built-in 'cd' command interprets the argument '/tmp'. If it exists and you have permission to enter, the prompt changes to 'john@laptop:/tmp$'. The shell updates its internal record of your current directory.

4

Listing Directory Contents with ls

You type 'ls -l' to list files in long format. The shell executes the external command 'ls' with the option '-l'. It reads the current directory's entries and displays them with permissions, owner, size, and modification date. You read the output to find a specific file.

5

Reading a File with cat

You type 'cat notes.txt' to print the contents of 'notes.txt' to the terminal. The shell runs the 'cat' command with the argument 'notes.txt'. The command reads the file from disk and sends its contents to the standard output (your screen), allowing you to see the file's text without opening a text editor.

6

Getting Help with man

You type 'man ls' to open the manual page for the 'ls' command. The shell runs the 'man' program, which reads a formatted documentation file. It displays detailed information about the command's purpose, all available options, and usage examples. You press 'q' to quit the manual and return to the prompt.

What This Looks Like on the Job

An IT professional managing a web server for an e-commerce company. The site is running slowly, and customers are complaining. Let us walk through how the command line is used to diagnose and fix this.

First, you open a terminal and SSH (secure shell) into the remote server. SSH is a command itself — 'ssh admin@webserver1.example.com'. This gives you a shell prompt on that machine, hundreds of miles away.

Your first step is to check system resources. You type 'top' to see a live view of CPU and memory usage. You immediately see a process called 'bad-php-script.php' consuming 95% of the CPU. You note its Process ID (PID), say 1234. You realise this is a runaway process.

Next, you use the command line to kill the offending process. You type 'kill 1234'. If it doesn't stop, you escalate to 'kill -9 1234', which forcefully terminates it. The CPU usage drops. The site recovers.

Now you need to investigate why it happened. You change to the logs directory: 'cd /var/log'. You list the log files: 'ls -lh'. You see 'nginx-access.log' and 'nginx-error.log'. You use 'tail -n 50 nginx-access.log' to see the last 50 requests to the web server. You see unusual traffic from a single IP address.

'tail -f nginx-access.log' allows you to follow the log in real-time as new requests come in.

You then use 'grep' to filter the logs: 'grep "192.168.1.100" nginx-access.log' finds all lines with that IP.

You use 'wc -l' to count how many lines: 'grep "192.168.1.100" nginx-access.log | wc -l' shows 5,000 requests in the last minute—this is a denial of service attack.

You block the IP using the firewall via the command line: 'iptables -A INPUT -s 192.168.1.100 -j DROP'. This adds a rule to drop all traffic from that IP.

Finally, you script the monitoring for the future. You write a small shell script using 'nano' (a command-line text editor) that checks CPU usage every minute and emails you if it exceeds a threshold. This script is saved as 'monitor.sh' and scheduled with 'cron' (a time-based job scheduler). This entire sequence—diagnosis, remediation, automation—is done without leaving the command line, demonstrating why this skill is indispensable.

How LPIC-1 Actually Tests This

The LPIC-1 exam (specifically exam 101) dedicates significant weight to 103.1. Expect roughly 8-12 questions on this topic. The exam does not test obscure commands; it tests understanding of core concepts and common command usage. Here is exactly what they focus on.

Key concepts they test relentlessly:

The shell prompt and its meaning ($ vs #).

Command structure: command, options, arguments. You must know that options modify behaviour and arguments are the targets.

Environment variables: especially PATH, HOME, USER, SHELL. You must know what they do and how to display them ('echo $VARIABLE', 'env').

Tab completion and command history (!, !!, history).

The difference between built-in commands and external commands (type command).

Quoting: single quotes (') preserve literal meaning, double quotes (") allow variable expansion and command substitution, backslash (\) escapes the next character.

Command chaining: ; (sequential), && (run next only if previous succeeds), || (run next only if previous fails).

The 'man' command to read manual pages.

Common traps they set:

Trapping you on quoting: they will give a command like 'echo '$HOME'' and ask what it outputs. The answer is the literal string '$HOME', not the value of the variable, because single quotes prevent expansion.

Confusing 'echo' with 'printf'. Echo is simpler and adds a newline.

Giving a bunch of 'ls' options like '-la' and asking what it does. You must know that '-l' gives long format, '-a' shows all (including . and ..).

Asking about the PATH variable: what happens if you remove the current directory (.) from PATH? You cannot run scripts in the current directory without typing './script'.

Environment variable persistence: changes made with 'export' are only for the current shell and its children. To make them permanent, you must edit '~/.bashrc' or '~/.profile'. This is a classic exam twist.

What you must memorise:

The difference between 'login shell' and 'non-login shell'. Login shells source '~/.profile', non-login shells source '~/.bashrc'.

The order of shell initialisation files: /etc/profile, ~/.profile, ~/.bashrc.

The 'source' command ('.') reads and executes a file in the current shell, not in a subshell.

Practice identifying the output of simple commands. For instance, what does 'echo My home is $HOME' print? Answer: My home is /home/username. Know that variables are expanded inside double quotes but not single quotes. These precision questions are the bread and butter of the exam.

Key Takeaways

The shell (typically Bash) interprets typed commands, and the prompt ($ for normal user, # for root) indicates your privilege level.

The basic command structure is always: command [options] [arguments] — options modify how the command runs, arguments specify what the command acts on.

Environment variables like $PATH and $HOME are set per-user and control where the shell looks for commands and what your home directory is.

Use single quotes (' ') to prevent any variable expansion or special interpretation within the quoted text.

The up arrow key and the 'history' command let you recall and re-run previous commands without retyping them.

Tab completion automatically fills in commands, filenames, and paths, saving time and preventing typos.

The 'man' command followed by a command name (e.g., 'man ls') opens the manual page with full documentation and options.

Commands chained with && (run next only if previous succeeds) and || (run next only if previous fails) allow basic conditional automation.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Single Quotes (' ')

All characters inside are literal — no variable expansion

Useful when you want to prevent any shell interpretation, e.g., 'echo $PATH' prints '$PATH'

Commonly used for strings containing special characters like $, `, or \

Double Quotes (" ")

Variables like $HOME are expanded to their values

Command substitution with `command` or $(command) is performed

Useful when you need to include variable values inside a string, e.g., "Your home is $HOME"

&& (AND operator)

Second command runs only if the first command succeeds (returns exit status 0)

Very useful for conditional sequences, like 'mkdir dir && cd dir'

Short-circuit evaluation: if first command fails, second is never executed

|| (OR operator)

Second command runs only if the first command fails (returns non-zero exit status)

Commonly used for error handling, like 'ping host || echo 'Host unreachable''

Short-circuit evaluation: if first command succeeds, second is skipped

Login Shell

Sourced configuration files: /etc/profile, then ~/.profile

Typically started when you log in via SSH or from a virtual console

Environment is set up for a full session, including things like umask and mail notifications

Non-Login Shell

Sourced configuration files: ~/.bashrc (often also /etc/bash.bashrc)

Typically started when you open a new terminal window from a desktop environment

Environment is inherited from the parent process; often faster to start

echo command

Simpler: prints arguments followed by a newline character

Limited formatting capabilities; no format specifiers

Most commonly used for simple output and debugging

printf command

More complex: prints formatted text using format specifiers like %s for strings and %d for numbers

Does not add a trailing newline unless you include \n in the format string

More powerful for structured output, but rarely tested in LPIC-1 beyond basic knowledge

Watch Out for These

Mistake

The command line is just typing commands; there's no structure or grammar to learn.

Correct

The command line has a strict syntax: command [options] [arguments]. Options modify behaviour (like -l for long list), arguments are targets (like a filename). Getting the order wrong or mixing them up causes errors.

Graphical interfaces create a habit of clicking randomly until something works, so beginners expect the command line to be equally forgiving.

Mistake

You must memorise every single command and its options to use the command line effectively.

Correct

You only need to know a few core commands (ls, cd, cp, mv, rm, man, echo) and how to use the manual pages ('man command') to look up options. Professionals constantly look things up; memorising is inefficient.

Fear of inadequacy — learners feel they must have encyclopedic knowledge to be legitimate, not realising that reference is part of the workflow.

Mistake

The $ in the prompt and the # in the prompt mean the same thing; it's just a decoration.

Correct

The $ indicates a normal user session with restricted permissions (cannot modify system files). The # indicates a root (superuser) session with full system privileges. Running commands as root can destroy your system.

Visually they are similar and many tutorials ignore the distinction, so beginners miss this critical security concept.

Mistake

Pressing Ctrl+C will close the terminal window entirely.

Correct

Ctrl+C sends the SIGINT (interrupt) signal to the currently running command, cancelling it. It does not close the terminal. To close the terminal, you type 'exit' or press Ctrl+D (which sends an EOF signal).

Experienced users say 'hit Ctrl+C to stop something', but beginners extrapolate that to mean it kills everything.

Mistake

Environment variables like PATH are the same for every user on the system and cannot be changed.

Correct

Every user has their own set of environment variables. You can change them temporarily with 'export PATH=/new/path:$PATH' or permanently by editing ~/.bashrc or ~/.profile.

The concept of user-specific settings is familiar from Windows (User Accounts), but Linux's per-user configuration files are not intuitive without explanation.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between a terminal and a shell?

A terminal (or terminal emulator) is the graphical window you type into. A shell is the program running inside that window that interprets your commands. Bash is a common shell; the terminal is just the container for it.

How do I run a command with multiple options?

You can combine them: 'ls -la' is the same as 'ls -l -a'. You can also group options with a single dash. Most commands also accept long options (like '--all') for clarity.

Why do I get 'command not found' when I type a command I know exists?

The shell cannot find the command because it is not in a directory listed in your PATH environment variable. Either the command is not installed, or you need to provide the full path (e.g., './script.sh' for a script in your current directory).

What do single quotes vs double quotes do?

Single quotes preserve every character literally — no variable expansion ($HOME stays as $HOME). Double quotes allow variable expansion ($HOME becomes /home/username) but still prevent globbing and word splitting. Use single quotes when you want the exact text, double quotes when you want variables substituted.

How do I cancel a command that is taking too long?

Press Ctrl+C to send the SIGINT (interrupt) signal, which terminates the currently running command and returns you to the prompt. If that fails, try Ctrl+Z to suspend it, then use 'kill %1' to terminate it properly.

What is the difference between a login shell and a non-login shell?

A login shell (like when you SSH into a server) reads configuration files from /etc/profile and ~/.profile. A non-login shell (like a terminal window from a desktop) reads ~/.bashrc. Certain environment variables may only be set in one type, so commands might behave differently depending on how you started the shell.

Terms Worth Knowing

Keep going

You've finished Command Line Basics and Shell Fundamentals. Continue through the LPIC-1 study guide to build a complete picture of the exam.

Done with this chapter?