| Tested on | RHEL 10.2 (Coughlan) |
|---|---|
| Package | bash 5.2.26-6.el10coreutils 9.5-8.el10_2man-db 2.12.0-10.el10which 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:
[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
cdandpwd. - Aliases are shortcuts the shell expands before running a command.
You can ask the shell how a name resolves before you run it:
type cdcd is a shell builtintype catcat is /usr/bin/catcd 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:
mkdir -p /tmp/cli-lab/docs /tmp/cli-lab/notes(no output on success)touch /tmp/cli-lab/docs/guide.txt /tmp/cli-lab/notes/readme.txt /tmp/cli-lab/notes/todo.txt(no output on success)cd /tmp/cli-labStay in this directory for the syntax, path, quoting, and glob sections below.
Understand Linux Command Syntax
A typical Linux command has three parts:
command [options] [arguments]- Command — the program or builtin name (
ls,mkdir,grep). Pattern matching withgrepis 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:
ls -ltotal 0
drwxr-xr-x. 2 root root 23 Aug 5 10:25 docs
drwxr-xr-x. 2 root root 40 Aug 5 10:25 notesThe same program often accepts a long option with the same meaning:
ls --format=longBoth 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:
ls docs notesLinux 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:
echo one two \
three fourone two three fourThe 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:
/tmp/cli-lab/docs/guide.txtA relative path starts from your current working directory:
docs/guide.txtSpecial directory names appear in almost every path:
| Symbol | Meaning |
|---|---|
/ |
Root of the filesystem |
. |
Current directory |
.. |
Parent directory |
~ |
Your home directory (expanded by the shell) |
Print and change directory
See where you are:
pwd/tmp/cli-labMove into a subdirectory with a relative path:
cd docscd succeeds silently when the directory exists. Confirm the change:
pwd/tmp/cli-lab/docsReturn to the parent directory:
cd ..(no output on success)Jump home from anywhere:
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:
lsdocs
notesAdd options for more detail:
ls -lLong 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:
echo 'literal $HOME'literal $HOMEDouble quotes still allow variable expansion and command substitution:
echo "expanded $HOME"expanded /rootUse 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:
echo "Today is $(date +%A)"Today is WednesdayWildcards at a glance
Unquoted * and ? are glob patterns the shell expands to matching file names in the current directory:
ls notes/*.txtnotes/readme.txt
notes/todo.txtIf 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:
type pwdpwd is a shell builtintype catcat is /usr/bin/catcommand -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:
command -v cat/usr/bin/catFor 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:
/usr/bin/which ls/usr/bin/lsUse 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:
whereis bashbash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gzLimitations 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:
history | tail -513 set +o posix
14 set +o verbose
15 set +o vi
16 set +o xtrace
17 history | tail -5Line 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:
ls --helpUsage: 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):
man lsLS(1) User Commands LS(1)
NAME
ls - list directory contentsInside 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:
info coreutilsFile: 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:
apropos "list directory"ls (1) - list directory contentsDistribution packages also place README files under /usr/share/doc. For bash on this system:
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
whoamirootiduid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023id 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:
su -s /bin/bash -c 'whoami; id -un' nobodynobody
nobodyThe -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
- GNU Bash manual — Shell Commands
- GNU Bash manual — Quoting
- GNU Coreutils manual — ls invocation
- POSIX command utility
- man7.org — path_resolution(7)
- man7.org — su(1)
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.

