RED HAT ENTERPRISE LINUX

The Linux Shell

Logging In and Running Simple Commands

CIS126RH | RHEL System Administration 1
Mesa Community College

Learning Objectives

Log in to a Linux system

Access systems via console, graphical, and remote methods

2
Understand the shell environment

What the shell is, how it interprets commands, and bash basics

3
Read and interpret the shell prompt

Understand username, hostname, directory, and privilege indicators

4
Run simple commands

Execute commands with options and arguments

What is the Shell?

The shell is a command-line interpreter that provides a user interface to the Linux operating system. It reads your commands, interprets them, and asks the kernel to execute them.

User
Shell
Kernel
Hardware

Command Line (Shell)

Text-based · Powerful and flexible
Scriptable · Works over remote connections
Low resource usage

Graphical (GUI)

Visual interface · Easier for beginners
Limited automation · Requires graphics
Higher resource usage

Bash — The Default Shell

Bash (Bourne Again SHell) is the default shell in RHEL. It is an enhanced version of the original Unix Bourne shell, combining features from C shell, Korn shell, and others.

Why Bash? Bash is ubiquitous — it is the default on RHEL, Ubuntu, macOS, and most Linux distributions. Skills you learn here transfer everywhere.

Bash — Checking Your Shell

# Check your current shell
[user@host ~]$ echo $SHELL
/bin/bash

# See available shells on the system
[user@host ~]$ cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash

# Check bash version
[user@host ~]$ bash --version
GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
The $SHELL variable shows your default login shell. /etc/shells lists every shell available on the system.

— Methods

MethodDescriptionWhen to Use
Physical terminal or virtual console (Ctrl+Alt+F1–F6)Direct hardware access, troubleshooting
Desktop environment (GNOME) login screenWorkstations, desktop use
Secure Shell remote connectionRemote server administration
GUI application providing shell accessShell access within graphical session
# SSH login to remote system
[user@local ~]$ ssh user@server.example.com
user@server.example.com's password:
Last login: Mon Jan 15 10:30:00 2024 from 192.168.1.100
[user@server ~]$

The

tty1 — Console Login
Red Hat Enterprise Linux 9.3 (Plow)
Kernel 5.14.0-362.el9.x86_64 on an x86_64

server login:
student
Password: ••••••••
Last login: Mon Jan 15 09:45:22 on tty2
[student@server ~]$
Security note: Your password is never displayed — not even asterisks. This prevents shoulder surfing attacks. Just type and press Enter.

The — Logging Out

# After successful login:
# - Shell environment is initialized
# - You are placed in your home directory
# - Shell prompt appears, ready for commands

# Log out when done
[student@server ~]$ exit
# Or press Ctrl+D (sends end-of-file signal)

# Switch between virtual consoles
# Ctrl+Alt+F2 through F6 — different consoles
# Ctrl+Alt+F1 (or F2) — return to graphical desktop
Always log out when finished. Leaving a session open on a shared system is a security risk.

Understanding the Prompt

The shell prompt tells you important information: who you are, what system you are on, where you are, and what privileges you have.

[student@server ~]$
   │       │     │ │
   │       │     │ └── $ = regular user  (# = root)
   │       │     └──── ~ = home directory (/home/student)
   │       └────────── server = hostname
   └────────────────── student = username

Reading the Prompt — Examples

# Regular user prompt
[student@server ~]$

# Root user prompt (note # instead of $)
[root@server ~]#

# In a different directory
[student@server Documents]$

# Full path might show instead of ~
[student@server /var/log]$
Important: The # prompt means you have root (administrator) privileges. Be extra careful — root can do anything, including accidentally destroying the system.

Command Structure

Linux commands follow a consistent structure: the command name, followed by options that modify behavior, followed by arguments that specify what to act on.

$ command  [-options]  [arguments]
     │          │           │
     │          │           └── What to act on (files, directories, etc.)
     │          └────────────── How to do it (modify behavior)
     └───────────────────────── What to do (the program to run)
# Command only
[user@host ~]$ date
Mon Jan 15 10:30:00 EST 2024

# Command with option
[user@host ~]$ date -u
Mon Jan 15 15:30:00 UTC 2024

Command Structure — Examples

# Command with argument
[user@host ~]$ echo Hello
Hello

# Command with option and argument
[user@host ~]$ ls -l /home
drwx------. 3 student student 4096 Jan 15 10:00 student

# Multiple options combined
[user@host ~]$ ls -la /home
total 12
drwxr-xr-x.  3 root    root     24 Jan 15 09:00 .
dr-xr-xr-x. 18 root    root   4096 Jan 15 09:00 ..
drwx------. 15 student student 4096 Jan 15 10:00 student
Not all commands require options or arguments. date works alone. Some commands require arguments — cp needs source and destination.

Options: Short and Long

# Short options: single dash, single letter
[user@host ~]$ ls -l
[user@host ~]$ ls -a
[user@host ~]$ ls -la        # Combined short options
[user@host ~]$ ls -l -a      # Same as above

# Long options: double dash, full word
[user@host ~]$ ls --all
[user@host ~]$ ls --human-readable
[user@host ~]$ ls -l --all   # Mix short and long

# Options with values
[user@host ~]$ head -n 5 file.txt      # Short: space or no space
[user@host ~]$ head --lines=5 file.txt # Long: use = sign

Options: Short and Long — Reference

ShortLongDescription
-a--allShow all (including hidden files)
-l(none)Long listing format
-h--human-readableHuman-readable sizes (KB, MB)
-r--reverseReverse sort order
Long options are helpful when learning — --human-readable is clearer than -h. In daily use, short options are faster to type. Check man COMMAND for all available options.

Your First Commands

# Display current date and time
[user@host ~]$ date
Mon Jan 15 10:30:00 EST 2024

# Show who you are logged in as
[user@host ~]$ whoami
student

# Display system hostname
[user@host ~]$ hostname
server.example.com

# Print working directory (where you are)
[user@host ~]$ pwd
/home/student
Tip: Try these commands right now! These are read-only — they only display information and cannot break anything.

Your First Commands (continued)

# Display text
[user@host ~]$ echo "Hello, World!"
Hello, World!

# Clear the terminal screen
[user@host ~]$ clear
# Or use Ctrl+L — same effect, faster

# Display a file's contents
[user@host ~]$ cat /etc/hostname
server.example.com
Practice these now. The best way to learn is by doing. Run each command and observe the output — you cannot break anything with these safe commands.

Essential Information Commands

# Who is logged into the system
[user@host ~]$ who
student  tty1         2024-01-15 09:00
root     pts/0        2024-01-15 09:30 (192.168.1.100)

# Detailed user and group IDs
[user@host ~]$ id
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)

# System information
[user@host ~]$ uname -a
Linux server 5.14.0-362.el9.x86_64 #1 SMP x86_64 GNU/Linux
The wheel group in id output is significant — membership grants sudo privileges in RHEL.

Essential Information Commands (continued)

# How long the system has been running
[user@host ~]$ uptime
10:30:00 up 5 days, 3:15, 2 users, load average: 0.15, 0.10, 0.08

# Current calendar
[user@host ~]$ cal
    January 2024
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
...

# Specific month and year
[user@host ~]$ cal 12 2024
uptime load averages: Three numbers showing system load over the last 1, 5, and 15 minutes. Numbers above the CPU count indicate the system is busy.

Listing Files: ls

# Basic listing
[user@host ~]$ ls
Desktop  Documents  Downloads  Music  Pictures  Videos

# Long format with details
[user@host ~]$ ls -l
drwxr-xr-x. 2 student student 4096 Jan 15 09:00 Desktop
drwxr-xr-x. 2 student student 4096 Jan 15 09:00 Documents
-rw-r--r--. 1 student student  123 Jan 15 10:00 notes.txt

# List a specific directory
[user@host ~]$ ls -l /var/log
The long format shows: file type + permissions, link count, owner, group, size, modification time, and name.

Listing Files: ls — More Options

# Show hidden files (start with .)
[user@host ~]$ ls -a
.  ..  .bash_history  .bashrc  Desktop  Documents  ...

# Human-readable sizes
[user@host ~]$ ls -lh
-rw-r--r--. 1 student student 4.5K Jan 15 10:00 file.txt
-rw-r--r--. 1 student student 2.1M Jan 15 10:00 image.jpg

# Combine all three
[user@host ~]$ ls -lah
Hidden files: Files starting with a dot (.) are hidden by default. Use -a to see them. These are typically configuration files like .bashrc.

Reading Files: cat

# Display entire file
[user@host ~]$ cat /etc/hostname
server.example.com

# Display multiple files in sequence
[user@host ~]$ cat file1.txt file2.txt

# Show line numbers
[user@host ~]$ cat -n /etc/passwd
     1  root:x:0:0:root:/root:/bin/bash
     2  bin:x:1:1:bin:/bin:/sbin/nologin
     ...
Warning: cat on a large file floods your terminal. Use head, tail, or less for large files.

Reading Files: head and tail

# Show first 10 lines (default)
[user@host ~]$ head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
...

# Show first 5 lines
[user@host ~]$ head -n 5 /etc/passwd

# Show last 10 lines
[user@host ~]$ tail /var/log/messages

# Follow file in real-time (great for logs)
[user@host ~]$ tail -f /var/log/messages
# Press Ctrl+C to stop following
Pro tip: tail -f is essential for watching log files in real time — you see new lines appear as events happen.

Command History

Bash remembers commands you have typed. Use history to recall and reuse previous commands — a huge time saver.

# Use Up/Down arrows to scroll through history
# Press Up arrow repeatedly to go back through commands

# View command history
[user@host ~]$ history
  1  date
  2  whoami
  3  ls -la
  4  cat /etc/hostname
  5  history

# Run command by number
[user@host ~]$ !3
ls -la

Command History — Search with Ctrl+R

# Run last command again
[user@host ~]$ !!

# Run most recent command starting with cat
[user@host ~]$ !cat

# Reverse search: Ctrl+R, then type
(reverse-i-search)`cat': cat /etc/hostname
# Press Ctrl+R again to find older matches
# Press Enter to run, or arrow keys to edit first
Ctrl+R magic: Press Ctrl+R and start typing any part of a past command. Bash searches your entire history backward for matching commands instantly.

Tab Completion

Tab completion is your best friend. Press Tab to automatically complete commands, file names, and paths. It saves typing and prevents typos.

# Type partial command, press Tab
[user@host ~]$ hostTab
hostname

# Type partial filename, press Tab
[user@host ~]$ cat /etc/hostTab
cat /etc/hostname

# Multiple matches: Tab Tab shows options
[user@host ~]$ cat /etc/passTabTab
passwd  passwd-

Tab Completion — Paths

# Complete directory paths
[user@host ~]$ ls /var/loTab
ls /var/log/

# Works for commands, files, directories, and more
[user@host ~]$ ls /var/log/messTab
ls /var/log/messages
Pro tip: If Tab does nothing, there are multiple matches. Press Tab twice to see all possibilities, then type more characters to narrow down. If Tab cannot complete it, it probably does not exist — which catches mistakes early.

Keyboard Shortcuts

ShortcutAction
Ctrl+CCancel current command / interrupt running process
Ctrl+DLog out (send EOF — end of file)
Ctrl+LClear screen (same as clear command)
Ctrl+AMove cursor to beginning of line
Ctrl+EMove cursor to end of line

Keyboard Shortcuts (continued)

ShortcutAction
Ctrl+UDelete from cursor to beginning of line
Ctrl+KDelete from cursor to end of line
Ctrl+WDelete word before cursor
Ctrl+RSearch command history (reverse search)
Ctrl+ZSuspend current process (send to background)
# Ctrl+C example: stop a running command
[user@host ~]$ tail -f /var/log/messages
(log output streaming...)
^C
[user@host ~]$

Multiple Commands

# Run commands sequentially with semicolon
[user@host ~]$ date; whoami; pwd
Mon Jan 15 10:30:00 EST 2024
student
/home/student

# Run second command only if first succeeds (&&)
[user@host ~]$ cd /tmp && ls
(lists /tmp contents)

# Run second command only if first fails (||)
[user@host ~]$ cd /nonexistent || echo "Directory not found"
bash: cd: /nonexistent: No such file or directory
Directory not found

Multiple Commands — Line Continuation

# Continue command on next line with backslash
[user@host ~]$ echo "This is a very long command that \
> continues on the next line"
This is a very long command that continues on the next line
Quick reference:
; — runs both commands regardless of success
&& — runs second only if first succeeds
|| — runs second only if first fails

Getting Help: man Pages

man (manual) pages are the built-in documentation for Linux commands. Every command should have a man page explaining its usage, options, and examples.

# Read the manual for a command
[user@host ~]$ man ls

LS(1)                     User Commands                    LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List information about the FILEs (the current directory
       by default).
...

Getting Help: Navigating man Pages

# Navigation in man pages (uses the less pager):
# Space or Page Down — next page
# b or Page Up     — previous page
# /pattern         — search for pattern
# n                — next search result
# q                — quit

# Man pages are in sections; specify section when needed
[user@host ~]$ man ls         # Section 1: user commands
[user@host ~]$ man 5 passwd   # Section 5: file formats
[user@host ~]$ man 8 useradd  # Section 8: admin commands
Remember: Press q to quit the man page and return to the shell. Use / to search within the page.

Other Help Methods

# Quick help — most commands support --help
[user@host ~]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs...
  -a, --all              do not ignore entries starting with .
  -l                     use a long listing format
...

# Whatis — one-line description
[user@host ~]$ whatis ls
ls (1)               - list directory contents
--help is shorter than a man page — good for a quick reminder of options. Some commands use -h instead.

Other Help Methods — Search

# Apropos — search for commands by keyword
[user@host ~]$ apropos directory
cd (1)               - change working directory
ls (1)               - list directory contents
mkdir (1)            - make directories
pwd (1)              - print name of current working directory
rmdir (1)            - remove empty directories
...

# Info pages (more detailed than man for some commands)
[user@host ~]$ info ls
When you know what you want to do, but not which command does it: use apropos KEYWORD. It searches all man page descriptions for that keyword.

Best Practices — Do

✔ Do

  • Use Tab completion constantly
  • Check the prompt before typing ($ vs #)
  • Read commands before pressing Enter
  • Use history and Ctrl+R to recall commands
  • Read man pages for unfamiliar commands
  • Start with safe, read-only commands
  • Log out when finished
  • Practice regularly to build skills

Best Practices — Do Not

✘ Do Not

  • Type commands without understanding them
  • Ignore error messages
  • Run commands from the internet blindly
  • Work as root unnecessarily
  • Leave sessions logged in unattended
  • Panic when something goes wrong
  • Skip reading the prompt (user vs root)
  • Give up — learning takes practice
Golden rule: If you do not understand what a command does, look it up before running it. This is especially important for commands copied from the internet.

Key Takeaways

Access via console, graphical, SSH, or terminal emulator. Password never displays. Use exit or Ctrl+D to log out.

2

The Shell: Bash is the command interpreter. It reads commands, executes them, and displays results.

3

The Prompt: [user@host dir]$ shows username, hostname, directory. $ = user, # = root.

4

Commands: Structure is command [-options] [arguments]. Use Tab completion, history, and man pages.

Graded Lab

  • Log in via console and SSH — examine and compare the prompts
  • Run basic commands: date, whoami, hostname, pwd, id
  • Practice ls with various options: -l, -a, -la, -lh
  • Use Tab completion to navigate the /etc directory
  • Search command history with Ctrl+R
  • Read man pages for date, ls, and cat

Next: Getting Help from Local Documentation