RH124 Chapter 2

Accessing the Command Line

CIS126RH · Red Hat System Administration I

The bash shell · Command syntax · Getting help

Goal: log in to RHEL's graphical and command-line environments and run simple commands correctly.

Chapter Objectives

Key commands: bash, pwd, echo, history, man, apropos, which

What Is the Shell?

The shell is a command interpreter.

  1. Reads what you type
  2. Runs the corresponding program
  3. Displays the results
  4. Shows a new prompt when ready

On RHEL, the default shell is bash — the Bourne Again SHell.

Why the Command Line Matters

The GUI is optional; the command line is not.

Most production RHEL servers are headless: they run without a graphical desktop.

Understanding the Shell Prompt

Regular user

[student@server1 ~]$

The prompt ends in $.

Root user

[root@server1 ~]#

The prompt ends in #.

Always check the prompt. A # means you are root and a mistyped command can damage the system.

Ways to Access a Terminal

MethodWhere / Use
GNOME TerminalGraphical desktop; local workstation
Virtual consoleCtrl+Alt+F3F6; direct login
SSHRemote network login
Text-mode boot targetServers without a GUI

Virtual Consoles

RHEL provides multiple virtual consoles.

Virtual consoles provide direct text-mode access without requiring a GUI.

Command Syntax

command [options] [arguments]

PartPurpose
commandThe program to run
optionsModify behavior; usually - or --
argumentsFiles, directories, or values the command acts on

Command Syntax Examples

pwd
ls -l
ls --all
ls -la
ls -l /etc

Quoting and Special Characters

The shell treats spaces, quotes, and characters such as *, $, and > specially.

echo Hello World
echo "Hello World"
echo '$HOME stays literal here'
echo "$HOME expands here"

Exam note: Single quotes are fully literal; double quotes still allow variable expansion and command substitution.

Command-Line Editing

ShortcutAction
Ctrl+AMove to start of line
Ctrl+EMove to end
Ctrl+UDelete from cursor to start
Ctrl+KDelete from cursor to end
Ctrl+RSearch command history
Ctrl+CCancel current command
↑ / ↓Move through history

Working with Command History

history
!482
!!

Ctrl+R is your friend: search backward through command history instead of pressing ↑ repeatedly.

Files and Paths

Commands can use absolute or relative paths.

Absolute

Starts from the root directory /.

cd /etc/ssh

Relative

Starts from the current directory.

cd ../ssh

Useful Directory Shortcuts

CommandMeaning
pwdShow current working directory
cd ~Go to your home directory
cd -Go to the previous directory
cd ..Go to the parent directory

Tab Completion

Press Tab while typing a command, file name, or path.

cd /etc/ss[Tab]
# becomes:
cd /etc/ssh/

Press Tab twice to list all possible matches when more than one exists.

Tab completion reduces typing, prevents path typos, and helps confirm that a file or directory exists.

Getting Help at the Command Line

ToolPurpose
manFull manual page for a command, file, or system call
--helpQuick summary of command options
aproposSearch man-page descriptions by keyword
whichShow the path to a command's executable

Help Command Examples

man ssh
ssh --help
apropos partition
which ssh

Navigating a man Page

KeyAction
SpaceScroll forward one page
bScroll backward one page
/patternSearch forward
nRepeat the last search
qQuit the man page

Man pages have sections. For the file-format version of passwd, use man 5 passwd.

Key Terms

shell
Command interpreter that reads, executes, and returns output.
bash
The Bourne Again SHell; RHEL's default shell.
prompt
Text shown when the shell is ready for input; ends in $ or #.
option
Flag that modifies command behavior.
argument
Value, file, or directory a command acts on.
absolute path
Path beginning at /.
relative path
Path interpreted from the current directory.
man page
Built-in manual documentation.

Check Your Understanding

  1. What is the difference between a $ prompt and a # prompt?
  2. Name two ways to reach a shell when no GUI is installed.
  3. How do single and double quotes handle $HOME differently?
  4. Name two ways to re-run a recent command.
  5. What does pressing Tab twice do?
  6. What is the difference between absolute and relative paths?
  7. How would you get the file-format version of the passwd man page?

Chapter 2 Takeaways

The goal is not to memorize every command. Learn how to work effectively at the shell and how to find the information you need.

← → / Space: navigate • Home/End: first/last • F: fullscreen