Linux Command Line Basics for Beginners

Tested on RHEL 10.2 (Coughlan)
Package bash 5.2.26-6.el10
coreutils 9.5-8.el10_2
man-db 2.12.0-10.el10
which 2.21-44.el10_0
Applies to Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, elementary OS, Zorin OS, Parrot OS, MX Linux, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora, Arch Linux
Privilege Normal user for most examples; root when demonstrating su
Scope Shell prompt anatomy, command syntax, paths, quoting, expansion, command lookup, history, tab completion, and built-in help tools. Covers basic login and su only — not sudo policy, file permissions, package management, or shell scripting depth.
Related guides Linux commands cheat sheet
which command
su command
sudo command
Shell scripting tutorial

The Linux command line is where you type instructions the shell can run, read their output, and chain small steps into real work. This lesson builds the mental model first — how a command is formed, how paths work, and how to find help — so later guides on redirection and pipes, files, permissions, and scripting make sense instead of feeling like memorized syntax. It opens the RHCSA tutorial course syllabus.


What Is the Linux Command Line?

Three terms show up together and mean different things:

  • Terminal — the text window (physical console, SSH session, or desktop terminal emulator) that shows characters you type and output from programs.
  • Shell — the program that reads each line, splits it into words, and runs commands. On most Linux systems the default login shell is bash.
  • Command-line interface (CLI) — working by typing commands and reading text output instead of clicking icons in a graphical desktop.

When you open a terminal you see a prompt. It usually tells you who you are, which host you are on, and where you are in the filesystem:

text
[user@host ~]$

The trailing $ is a common hint that you are a normal user. A # prompt often means root, though your distribution may color prompts differently.

Commands, builtins, and external programs

Not every command name starts a separate program file:

  • External programs live on disk, for example /usr/bin/ls.
  • Shell builtins are handled inside bash itself, for example cd and pwd.
  • Aliases are shortcuts the shell expands before running a command.

You can ask the shell how a name resolves before you run it:

bash
type cd
output
cd is a shell builtin
bash
type cat
output
cat is /usr/bin/cat

cd never creates a new process — bash changes its own working directory. cat runs the executable file at the path type reports.


Prepare the Practice Directory

The path, navigation, and glob examples below use a small tree under /tmp/cli-lab. Create it once before you continue:

bash
mkdir -p /tmp/cli-lab/docs /tmp/cli-lab/notes
output
(no output on success)
bash
touch /tmp/cli-lab/docs/guide.txt /tmp/cli-lab/notes/readme.txt /tmp/cli-lab/notes/todo.txt
output
(no output on success)
bash
cd /tmp/cli-lab

Stay in this directory for the syntax, path, quoting, and glob sections below.


Understand Linux Command Syntax

A typical Linux command has three parts:

text
command [options] [arguments]
  • Command — the program or builtin name (ls, mkdir, grep). Pattern matching with grep is covered in the grep command guide; here you only need how options and arguments attach to any command name.
  • Options — modify behavior. Short form uses one hyphen and one letter (-l). Long form uses two hyphens (--help).
  • Arguments — values the command acts on, such as file names or paths.

Options that need a value are written as -o value or --option=value.

Short and long options

List the current directory in long format:

bash
ls -l
output
total 0
drwxr-xr-x. 2 root root 23 Aug  5 10:25 docs
drwxr-xr-x. 2 root root 40 Aug  5 10:25 notes

The same program often accepts a long option with the same meaning:

bash
ls --format=long

Both forms ask ls for a detailed listing. Long options are easier to read in scripts; short options are faster to type interactively.

Multiple arguments and case sensitivity

Many commands accept several arguments in one line:

bash
ls docs notes

Linux treats upper and lower case as different characters. ls, LS, and Ls are three different names. Option letters are case sensitive too: -l and -L are not interchangeable on ls.

Continue a long command on the next line

When a command does not fit comfortably on one line, end the line with a backslash and press Enter. The shell waits for the rest:

bash
echo one two \
  three four
output
one two three four

The backslash must be the last character on the line — no spaces after it.


Work with Paths in Linux

Every file and directory on Linux sits in a single tree that starts at /, the root directory. You reach a file by path: the sequence of directory names from / down to that file.

Absolute and relative paths

An absolute path always starts with / and does not depend on where you are now:

text
/tmp/cli-lab/docs/guide.txt

A relative path starts from your current working directory:

text
docs/guide.txt

Special directory names appear in almost every path:

Symbol Meaning
/ Root of the filesystem
. Current directory
.. Parent directory
~ Your home directory (expanded by the shell)

See where you are:

bash
pwd
output
/tmp/cli-lab

Move into a subdirectory with a relative path:

bash
cd docs

cd succeeds silently when the directory exists. Confirm the change:

bash
pwd
output
/tmp/cli-lab/docs

Return to the parent directory:

bash
cd ..
output
(no output on success)

Jump home from anywhere:

bash
cd ~

Your home directory is stored in the HOME variable. cd with no arguments also returns home on bash.

List directory contents

From the lab directory, list names only:

bash
ls
output
docs
notes

Add options for more detail:

bash
ls -l

Long listings show permissions, owner, size, and modification time — enough to confirm you are in the right place before you edit text files from the command line or remove paths you no longer need. Broader copy, move, and delete workflows stay in dedicated file-management guides; here you only need navigation and inspection.


Use Quoting and Shell Expansion

Before Bash runs a command, it parses the line into tokens, performs expansions such as variable and command substitution, applies word splitting and filename expansion where quoting permits, and finally removes the quote characters. Quoting controls which steps run.

Single versus double quotes

Single quotes preserve every character literally:

bash
echo 'literal $HOME'
output
literal $HOME

Double quotes still allow variable expansion and command substitution:

bash
echo "expanded $HOME"
output
expanded /root

Use quotes when spaces or $, `, *, or ? belong to your data. Without quotes the shell treats them as syntax.

Tilde, variable, and command substitution

The shell expands ~ to your home directory before most commands run. Variable expansion replaces $NAME with the variable value. Command substitution runs a nested command and inserts its output:

bash
echo "Today is $(date +%A)"
output
Today is Wednesday

Wildcards at a glance

Unquoted * and ? are glob patterns the shell expands to matching file names in the current directory:

bash
ls notes/*.txt
output
notes/readme.txt
notes/todo.txt

If no file matches, bash leaves the pattern unchanged and the command may report “No such file”. Quoting disables globbing: echo '*.txt' prints the two characters * and .txt literally.


Find and Identify Linux Commands

When you are unsure what a name does, resolve it before you run it — especially on shared systems where aliases may change behavior.

type and command -v

type is a bash builtin that explains how the shell would run a name:

bash
type pwd
output
pwd is a shell builtin
bash
type cat
output
cat is /usr/bin/cat

command -v prints how the shell resolves a name and is the preferred form for scripts. Depending on the shell configuration, it may print an alias, builtin name, function, or executable path:

bash
command -v cat
output
/usr/bin/cat

For human-readable detail on the same resolution, command -V (uppercase) prints a longer description similar to type. Reserve -V for interactive troubleshooting; use -v when a script needs a path or name it can pass to another program.

which and whereis

which searches directories in your PATH environment variable and prints the first executable it finds:

bash
/usr/bin/which ls
output
/usr/bin/ls

Use the full path /usr/bin/which when documenting examples — interactive shells often alias which to add alias and function awareness. See the dedicated which command guide for PATH edge cases.

whereis looks broader: binary, source, and man page locations:

bash
whereis bash
output
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz

Limitations of which

which does not understand shell builtins or functions unless your shell expanded them first. That is why which cd often prints nothing useful even though cd works. Prefer type or command -v in scripts; use which when you specifically need the on-disk path of an external program.


Use Command History and Tab Completion

bash remembers commands you typed in the current session and across sessions (when configured). Combined with tab completion, history saves time without sacrificing accuracy.

Browse and search history

Press Up and Down to move through previous commands. Search interactively with Ctrl+R, type a fragment of an old command, and press Enter when you see the line you need.

List the most recent entries:

bash
history | tail -5
output
13  set +o posix
   14  set +o verbose
   15  set +o vi
   16  set +o xtrace
   17  history | tail -5

Line numbers let you re-run a specific entry with !17 after you verify the text — a typo in history can repeat a destructive command.

Tab completion

Press Tab once to complete a command name, path, or option when the match is unique. Press Tab twice to list ambiguous choices. Completion reduces typos in long paths such as /usr/share/doc.


Find Help for Linux Commands

Linux ships documentation on the system itself. You do not need to memorize every flag.

Quick syntax with --help

Many GNU programs print a short usage summary:

bash
ls --help
output
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.

--help exits immediately and fits on one screen. It is the fastest check when you forgot a single option.

Manual pages with man

man opens the full manual in a pager (usually less):

bash
man ls
output
LS(1)                            User Commands                           LS(1)

NAME
       ls - list directory contents

Inside the pager, press /, type a keyword, and press Enter to search forward. Press q to quit. Section numbers matter: man 5 passwd documents the /etc/passwd file format, while man 1 passwd documents the user command.

info, apropos, and /usr/share/doc

GNU projects often publish longer info manuals. The info program is the viewer; each package may ship its own Info pages separately. On RHEL you may need the info package for the viewer, and documentation for a specific tool appears only when that package installs Info files under /usr/share/info.

Open the Coreutils manual as an example:

bash
info coreutils
output
File: coreutils.info,  Node: Top,  Up: (dir)

Core GNU utilities

This manual documents the GNU core utilities.

Press q to exit the Info reader. If info coreutils reports that no menu item exists, install the viewer on RHEL with dnf (info package) and confirm the package that owns the command also installed its Info documentation.

When you know a task but not the command name, search manual page names and descriptions:

bash
apropos "list directory"
output
ls (1)              - list directory contents

Distribution packages also place README files under /usr/share/doc. For bash on this system:

bash
ls /usr/share/doc/bash*/

Package maintainers use that directory for release notes and examples that do not fit in man.


Log In and Switch Users

Linux is multi-user. Your prompt shows the effective user for the current shell session.

Local login and remote sessions

Login starts a new session after authentication — at the physical console, through a display manager, or over SSH. The ssh command covers remote shells in depth; locally, the login program (or an equivalent such as sshd) validates credentials and starts your login shell.

In an existing terminal you normally do not run login by hand. Instead you open a new session or use su to change identity inside the current environment.

Check who you are

bash
whoami
output
root
bash
id
output
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

id adds numeric IDs and group membership — useful when a command behaves differently for root.

Basic su

su starts a shell as another user. By default it targets root and often expects that user's password. For command syntax and login-shell options, see the su command guide. The example below switches to the unprivileged nobody account for one command — run it from a root shell, because nobody normally has no login password and the -s shell override may be ignored for restricted accounts when the caller is not root:

bash
su -s /bin/bash -c 'whoami; id -un' nobody
output
nobody
nobody

The -s option chooses the shell binary. The -c option runs one command instead of opening an interactive session.

Login shell versus non-login shell matters: su - username (or su -l) loads that user's full login environment, similar to a fresh console login. su username without - keeps more of your current shell settings.

For day-to-day privileged tasks on modern systems, administrators usually configure sudo instead of sharing the root password. This article stops at basic su so the dedicated sudo guide can cover policy files and safe elevation.


Linux Command Line Quick Reference

These are the foundational commands exercised in this lesson. For a site-wide index of file, process, and networking commands, use the Linux commands cheat sheet.

Task Command
Show current directory pwd
Change directory cd path
List names ls
Long listing ls -l
Command resolution type name
Portable lookup command -v name
PATH lookup /usr/bin/which name
Binary, source, man paths whereis name
Short built-in help help name
Program usage summary command --help
Full manual man command
Search manual titles apropos keyword
Effective username whoami
User and group IDs id
Run as another user su -s /bin/bash -c 'command' user
Command history history

References


Summary

You now have a working picture of how the Linux command line fits together: the terminal shows text, bash interprets each line, and external programs plus shell builtins do the actual work. Syntax is predictable — command, options, arguments — and paths are either absolute from / or relative from your current directory, with ., .., and ~ saving keystrokes once you know what they expand to.

Quoting and expansion are the usual surprise for beginners. Single quotes freeze text; double quotes still let variables and $(...) expand; unquoted * patterns match file names in the current directory. When you are unsure what a name will run, type and command -v beat which for builtins, and man plus --help beat guessing flags from memory. For switching to another user account, see the su section above. From here, put those paths and * patterns to work in create, copy, move and delete files, then move on to file permissions and, when you are ready, the shell scripting tutorial. Keep the cheat sheet open as a map, not a substitute for understanding how the shell parses each line you type.


Frequently Asked Questions

1. What is the difference between the terminal, the shell, and the command line?

The terminal is the window or device that displays text. The shell is the program that reads your input and runs commands — bash is the default on most Linux systems. Command line means working through typed commands instead of a graphical desktop.

2. What is the difference between an absolute path and a relative path?

An absolute path starts from the root directory / and never depends on your current location. A relative path starts from the directory you are in now and uses names like . for the current directory or .. for the parent directory.

3. Should I use which or type to find a command?

Prefer type or command -v inside scripts because they understand shell aliases, functions, and builtins. which only searches PATH for executable files and can miss builtins such as cd and pwd.

4. When do I need single quotes versus double quotes?

Single quotes preserve every character literally. Double quotes still prevent word splitting but allow variable expansion and command substitution. Use quotes when spaces or special characters are part of the data, not when they are shell syntax.

5. Is Linux case sensitive at the command line?

Yes. Command names, file names, and option letters are case sensitive. ls and LS are not the same command, and -l is not the same option as -L.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)