College-Level Course Module | RHEL System Administration
Learning Objectives
1
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 interface Powerful and flexible Scriptable and automatable Works over remote connections Low resource usage
Bash (Bourne Again SHell) is the default shell in RHEL. It is an enhanced version of the original Unix Bourne shell with features from other shells like C shell and Korn 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)
Why Bash? Bash is ubiquitous - it's the default on RHEL, Ubuntu, macOS, and most Linux distributions. Skills you learn transfer everywhere.
Logging In - Methods
Method
Description
When to Use
Console
Physical terminal or virtual console (Ctrl+Alt+F1-F6)
Direct hardware access, troubleshooting
Graphical
Desktop environment (GNOME) login screen
Workstations, desktop use
SSH
Secure Shell remote connection
Remote server administration
Terminal Emulator
GUI application providing shell access
Shell 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 ~]$# Switch to different virtual console: Ctrl+Alt+F2 through F6# Return to graphical desktop: Ctrl+Alt+F1 (or F2 on some systems)
The Login Process
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 ~]$
# Login prompts for:# 1. Username - your account name# 2. Password - not displayed as you type (security)# After successful login:# - Shell environment is initialized# - You're placed in your home directory# - Shell prompt appears, ready for commands# Log out when done[student@server ~]$ exit
# Or press Ctrl+D
Security note: Your password is never displayed - not even asterisks. This prevents shoulder surfing attacks. Just type and press Enter.
Understanding the Prompt
The shell prompt tells you important information: who you are, what system you're on, where you are, and what privileges you have.
# Regular user prompt[student@server ~]$# Root user prompt (note the # instead of $)[root@server ~]## In 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 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
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 -n5 file.txt # Also valid[user@host ~]$ head --lines=5 file.txt # Long: use = sign
Short
Long
Description
-a
--all
Show all (including hidden)
-l
(none)
Long listing format
-h
--human-readable
Human-readable sizes
-r
--reverse
Reverse order
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# Display text[user@host ~]$ echo "Hello, World!"
Hello, World!# Clear the terminal screen[user@host ~]$ clear
Tip: Try these commands right now! The best way to learn is by doing. 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# How long 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
...
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# 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# List specific directory[user@host ~]$ ls -l /var/log
Hidden files: Files starting with a dot (.) are hidden by default. Use -a to see them. These are often configuration files.
Reading Files: cat, head, tail
# Display entire file[user@host ~]$ cat /etc/hostname
server.example.com# Display multiple files[user@host ~]$ cat file1.txt file2.txt
# 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
Warning:cat on a large file floods your terminal. Use head, tail, or less for large files.
Command History
Bash remembers commands you have typed. Use the history feature 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(output of ls -la)# Run last command[user@host ~]$ !!
# Search history: Ctrl+R, then type(reverse-i-search)`cat': cat /etc/hostname
Ctrl+R magic: Press Ctrl+R and start typing. Bash searches your history for matching commands. Press Ctrl+R again to find older matches.
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 ~]$ hostTabhostname# Type partial filename, press Tab[user@host ~]$ cat /etc/hostTabcat /etc/hostname# Multiple matches: Tab Tab shows options[user@host ~]$ cat /etc/passTabTabpasswd passwd-# Complete directory paths[user@host ~]$ ls /var/loTabls /var/log/# Works for commands, files, directories, and more
Pro tip: If Tab does nothing, there are multiple matches. Press Tab twice to see all possibilities. Type more characters to narrow down.
Keyboard Shortcuts
Shortcut
Action
Ctrl+C
Cancel current command / interrupt running process
# 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# 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. && 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).
...# Navigation in man pages:# Space or Page Down - next page# b or Page Up - previous page# /pattern - search for pattern# n - next search result# q - quit
Remember: Press q to quit the man page and return to the shell.
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# 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
Best Practices
Do
Use Tab completion constantly
Check the prompt before typing
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
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 from the internet.
Key Takeaways
1
Logging In: 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.