CIS126RH  ·  Lab Exercise

Introduction to the
Linux Command Line

Your first session in the shell — reading files, moving data, and staying oriented.

Before you begin: Log in to your RHEL workstation. Every command in this lab is entered at the shell prompt. Type each command exactly as shown — Linux is case-sensitive.

Part 1

Understanding the Shell Prompt

STEP 01 Read the prompt

When you log in, the shell greets you with a prompt — a short line of text that tells you who you are, what machine you are on, and that it is ready for your command.

student@workstation $
studentYour username — who is logged in
@Separator — read as "at"
workstationHostname — the name of this machine
$Indicates a regular (non-root) user. Root users see # instead.
✓ Check: Confirm your prompt looks like student@workstation $ before continuing.

Part 2

Commands and Options

STEP 02 Anatomy of a command

A Linux command follows a consistent structure:

command -option argument
command The program to run
-option Modifies how the command behaves (preceded by a dash)
argument The file, directory, or data the command acts on

Try a real example — clear your command history:

$ history -c

Here history is the command and -c is the option that clears the saved history list. No output is produced when it succeeds — that is normal.

Part 3

Displaying File Contents

STEP 03 View the first 10 lines of a file with head

Large files are impractical to display all at once. head shows just the first 10 lines — useful for peeking at what a file contains.

$ head /usr/share/doc/bash/FAQ
This is the Bash FAQ, version 4.15, for Bash version 5.1
...

The argument here is an absolute path — starting from / (the root of the filesystem) all the way to the file named FAQ.

STEP 04 View the last 10 lines of a file with tail

tail is the counterpart to head. It shows the last 10 lines, which is especially handy for log files where the most recent events appear at the bottom.

$ tail /usr/share/doc/bash/FAQ
This document is Copyright 1995-2014 by Chester Ramey.
...
✓ Check: The last line you see should reference a copyright statement. If you got an error, double-check the path — remember, Linux paths are case-sensitive.

Part 4

Copying, Moving, and Removing Files

STEP 05 Copy a file to the current directory with cp

The cp command copies a file. The destination is the second argument. A single dot . is shorthand for the directory you are currently in.

$ cp /usr/share/doc/bash/FAQ .

After this command you will have a personal copy of the FAQ file in your current directory. The original file in /usr/share/doc/bash/ is untouched.

Key symbol: . (dot) — refers to the current directory.
Key symbol: .. (double dot) — refers to the parent directory (one level up).
STEP 06 Move a file to the parent directory with mv

mv moves (or renames) a file. Unlike cp, the original location no longer has the file after the operation.

$ mv /usr/share/doc/bash/FAQ ../

The destination ../ means "one directory above the current one." The file is moved there.

Heads up: On a shared or read-only system you may not have permission to move system files from /usr/share. Your instructor will advise if a substitute path should be used.
STEP 07 Delete a file permanently with rm

rm removes a file. There is no Recycle Bin — once deleted, the file is gone. The -i option adds an interactive confirmation prompt to protect you from accidents.

$ rm -i FAQ
rm: remove regular file 'FAQ'? y

Type y and press Enter to confirm. Type n to cancel.

✓ Check: After confirming, the file is deleted. Run ls to confirm it no longer appears in the directory listing.

Part 5

Keeping Your Terminal Tidy

STEP 08 Clear the screen with clear

After several commands the terminal can feel cluttered. clear scrolls all previous output off-screen and places a fresh prompt at the top.

$ clear

Nothing is deleted — you can still scroll up to see prior output. The keyboard shortcut Ctrl + L does the same thing.

STEP 09 Review your session with history

The shell keeps a numbered list of every command you have typed. Running history displays it — a great way to review what you did or re-run a command.

$ history
1 history -c
2 head /usr/share/doc/bash/FAQ
3 tail /usr/share/doc/bash/FAQ
4 cp /usr/share/doc/bash/FAQ .
5 rm -i FAQ
6 clear
7 history

To re-run any listed command, type ! followed by its number. For example, !3 re-runs the tail command.

✓ Check: You should see at least the commands from this lab listed. If you see only one or two entries, you may have cleared history earlier — that is fine.

Summary

Commands Covered in This Lab

Command What it does Example
history -c Clears the saved command history history -c
head Shows the first 10 lines of a file head /usr/share/doc/bash/FAQ
tail Shows the last 10 lines of a file tail /usr/share/doc/bash/FAQ
cp Copies a file to a destination cp /usr/share/doc/bash/FAQ .
mv Moves (or renames) a file mv FAQ ../
rm -i Deletes a file (asks for confirmation) rm -i FAQ
clear Clears the terminal screen clear
history Lists recently used commands history
Path shortcuts to remember:  . = current directory  ·  .. = parent directory  ·  / = root of the filesystem