2.1 Shell Prompt and Command Syntax
Key Takeaways
- RHEL 10 default interactive shell is bash; the prompt tells you who you are, where you are, and whether you have root privileges ($ vs #).
- Command line order is command, options (short -x or long --name), then arguments (paths, names, patterns); getopts-style flags usually come before operands.
- Tab completion, history (!!, Ctrl-R), and Ctrl-C / Ctrl-D / Ctrl-Z are exam speed tools—use them deliberately under time pressure.
- Absolute paths start at /; relative paths start from $PWD. Always confirm identity with whoami and id before destructive work.
- Quote arguments with spaces or shell metacharacters; unquoted * ? [ ] $ ` and similar expand before the command runs.
2.1 Shell Prompt and Command Syntax
Quick Answer: On RHEL 10, open a terminal or SSH session, confirm you are in bash, read the prompt for user and path, then run
command [options] [arguments]with correct quoting and paths. Root sessions usually show#; regular users show$.
The EX200 objective Access a shell prompt and issue commands with correct syntax is the first essential-tools skill. Every graded task—editing configs, managing storage, fixing SELinux—starts at a prompt. There is no partial credit for “almost right” syntax; a mistyped path or unquoted space fails the command and burns time.
Opening a Shell on RHEL 10
In the exam VM you typically land in a graphical session or a text console. From the GUI, open Terminal (or press the standard shortcut if available). From a text console, log in with the account the task describes. Remote access is covered later under SSH; locally, you may already be logged in as a normal user and escalate with sudo or su - when a task requires root.
Confirm the shell and identity immediately:
echo $SHELL
ps -p $$
whoami
id
pwd
$SHELL is the login shell path (often /bin/bash on RHEL). ps -p $$ shows the current process; on exam systems you should see bash. whoami and id print the effective user and groups—critical before changing ownership, writing under /etc, or using privileged tools. pwd prints the working directory; many tasks assume you start in a home directory and navigate deliberately.
Switch to root only when needed:
sudo -i # root login shell via sudo (preferred pattern on modern RHEL)
su - # root login shell if password policy allows
exit # leave root shell; return to previous user
Exam trap: Running as root by default makes every typo more dangerous. Prefer a normal user plus sudo for single commands unless the task requires a full root environment (for example, some recovery or multi-step system config work).
Reading the Prompt
A typical bash prompt on RHEL looks like:
[student@server1 ~]$
[root@server1 /etc]#
Break it down:
| Prompt piece | Meaning |
|---|---|
student / root | Current user |
server1 | Hostname (short form) |
~ or /etc | Working directory (~ means home) |
$ | Unprivileged shell |
# | Root shell |
If the prompt shows # and you thought you were a normal user, stop and re-check whoami before proceeding. If the hostname is wrong, you may be on the wrong machine in multi-VM scenarios—confirm before changing production-like configs.
Customize temporarily for clarity during practice (not required on exam):
export PS1='[\u@\h \w]\$ '
\u user, \h hostname, \w full working path, \$ shows $ or # based on UID.
Command Syntax Anatomy
Bash parses a simple command as:
command [options...] [arguments...]
Examples:
ls
ls -la /var/log
ls --all --human-readable /var/log
cp -a /etc/hosts /tmp/hosts.bak
systemctl status sshd
- Command: the program or shell builtin (
ls,cp,cd,echo). - Options (flags): modify behavior. Short form is one dash plus letter (
-l,-a); long form is two dashes (--all). Combined short options are common:ls -laequalsls -l -a. - Arguments: operands the command acts on—file paths, usernames, service names, patterns.
Option order matters for some tools but not all. A safe exam habit is options first, then operands:
grep -i error /var/log/messages
# not: grep /var/log/messages -i error (works for grep but confuses habits)
Many GNU utilities accept -- to mark end of options when an argument looks like a flag:
rm -- -weirdfile
Paths: Absolute vs Relative
| Form | Example | Resolves from |
|---|---|---|
| Absolute | /etc/ssh/sshd_config | Filesystem root / |
| Relative | sshd_config | Current directory $PWD |
| Home shortcut | ~/notes.txt | Current user’s home |
| Parent | ../backup | One directory up |
| Current | ./script.sh | Explicit current directory |
cd /etc
ls ssh/sshd_config # relative from /etc
ls /etc/ssh/sshd_config # absolute—works from anywhere
cd ~
cd -
cd - returns to the previous directory—useful when alternating between two paths. cd with no argument goes home.
Exam trap: Relative paths fail silently or act on the wrong file when you are not where you think you are. Before long pipelines, run pwd and use absolute paths for critical system files.
Quoting and Metacharacters
The shell expands certain characters before the command runs:
| Character | Risk if unquoted |
|---|---|
| space | Splits one argument into many |
* ? [...] | Filename globbing |
$VAR / $(...) | Parameter / command substitution |
> >> < | | Redirection / pipe (next section) |
; & | Command separators / background |
` | Legacy command substitution |
Quoting rules you need:
touch "My Report.txt"
echo "User is $USER" # double quotes: variables expand
echo 'User is $USER' # single quotes: literal text
echo Files: *.conf # glob expands to matching names
echo 'Files: *.conf' # literal asterisk
Use single quotes when you must protect $ and backticks. Use double quotes when you want expansion but need to protect spaces. Escape a single character with backslash: echo \$HOME prints $HOME.
Essential Navigation and Inspection Commands
Memorize these for fluid exam work:
pwd # print working directory
cd /path # change directory
ls -la # long list including hidden files
ls -ld /etc # list directory itself, not contents
file /bin/bash # identify file type
stat /etc/passwd # inode, permissions, timestamps
which systemctl # path of executable in $PATH
type cd # shell builtin vs external command
hash -r # clear command path cache after PATH changes
type is underrated on RHCSA: it tells you whether a name is a builtin, alias, function, or external binary. If a command “doesn’t work” after installing a package, re-check type and $PATH.
Line Editing, History, and Job Control
Speed matters on a timed performance exam:
| Key / shortcut | Effect |
|---|---|
| Tab | Complete command, option, or path |
| Tab Tab | List possible completions |
| Up / Down arrow | Previous / next history line |
Ctrl-R | Reverse incremental history search |
!! | Re-run last command |
!$ | Last argument of previous command |
Ctrl-A / Ctrl-E | Start / end of line |
Ctrl-U | Kill from cursor to start of line |
Ctrl-C | Interrupt running foreground process |
Ctrl-D | EOF / logout of interactive shell (empty line) |
Ctrl-Z | Suspend job (then bg / fg / jobs) |
ls /var/log/messages
less !$ # less /var/log/messages
sudo !! # re-run last command with sudo
Exam trap: Ctrl-D on an empty prompt logs you out. If you meant to stop input to a program, ensure you are inside that program’s stdin, not at a bare shell prompt.
Command Exit Status
Every command returns an integer exit status in $?:
true; echo $?
false; echo $?
ls /no/such/path; echo $?
0means success.- Non-zero means failure (exact codes vary by program).
You will use exit status heavily in shell scripting later (if, &&, ||). At the prompt, check $? after a failed command instead of re-running blindly:
cp src dest || echo "copy failed with $?"
Practical Scenario: “Configure as User X in Directory Y”
Task wording often assumes:
- You are logged in as a specific user (or switch with
su - username). - You work in a named directory under that user’s home or under
/home. - Files must be owned by that user unless told otherwise.
Workflow:
whoami
id
cd /home/student/project || mkdir -p /home/student/project && cd /home/student/project
pwd
touch notes.txt
ls -l notes.txt
If ownership is wrong because you created files as root:
sudo chown student:student notes.txt
Creating files as root under a user home is a classic exam self-own—fix it before grading yourself.
Common Syntax Mistakes That Cost Points
- Spaces around
=in assignments —VAR = valueruns commandVAR; useVAR=value. - Forgetting spaces in
test/[ ]—[ -f file ]needs spaces; covered in scripting chapters. - Wrong dash characters — paste from docs can insert en-dashes; type
-yourself. - Assuming Windows paths — RHEL uses
/, not\. - Running GUI-only mental models — there is no “undo” tray; verify with
ls,cat,systemctl statusafter each change.
RHEL 10 Notes
RHEL 10 continues the bash-as-default interactive shell model familiar from RHEL 8/9. Coreutils commands (ls, cp, mv, chmod, …) behave as GNU tools. Do not rely on non-RHEL aliases from personal laptops (ll may or may not exist depending on profile). Prefer portable forms: ls -la over assuming ll.
When documentation is needed at the prompt:
man ls
man bash
info coreutils 'ls invocation'
System documentation is its own objective later; for this section, know that man 1 command is your syntax source of truth when memory blanks under pressure.
Section Checkpoint
Before leaving this skill, you should be able to open a shell, identify user and path from the prompt, run commands with short and long options, navigate with absolute and relative paths, quote filenames with spaces, recover previous commands from history, and interpret $? after failures. Those habits make every later RHCSA task faster and safer.
On a RHEL 10 system, a prompt ends with # and whoami prints root. What does this indicate about the shell session?
You are in /home/student and must edit /etc/hosts. Which approach best avoids path mistakes under exam pressure?
Which command line correctly creates a file whose name contains a space?
After a command fails, which expansion shows the exit status of the last foreground command?