File Viewing & Editing – Linux Teaching Plan

This 3‑hour workshop introduces the most common Linux utilities for inspecting and modifying files. It is ideal for students who already know how to navigate a filesystem but need to learn how to read, search, and edit text data in a console‑only environment.

Learning Objectives

Schedule Overview

  1. 0‑10 min – Intro & agenda
  2. 10‑25 min – Basic file viewing: cat, less, more
  3. 25‑40 min – Quick heads/tails: head, tail
  4. 40‑55 min – Pattern search: grep
  5. 55‑70 min – Streaming edits: sed
  6. 70‑85 min – Column processing: awk
  7. 85‑100 min – Editing with nano and vim
  8. 100‑115 min – Comparing files: diff, comm
  9. 115‑120 min – Wrap‑up & assessment

Command Topics & Hands‑On Exercises

1. cat – Concatenate & Display

Displays the entire contents of a file on standard output.

cat README.md

Combine multiple files:

cat file1.txt file2.txt > merged.txt

2. less – Page‑wise Viewer

Allows forward/backward navigation through large files.

less /var/log/syslog

Search inside the file:

/error

3. more – Simple Pager

Older, less feature‑rich pager. Good for quick one‑page look.

more greeting.txt

5. tail – Show Last Lines

Prints the last 10 lines by default.

tail /var/log/kern.log

Follow a file in real‑time:

tail -f /var/log/syslog

6. grep – Pattern Search

Finds lines matching a pattern (regular expression).

grep -i "error" /var/log/syslog

Recursive search:

grep -r "TODO" .

7. sed – Stream Editor

Performs in‑place or streamed transformations.

sed 's/foo/bar/g' file.txt

Delete lines:

sed '/^#/d' file.txt

8. awk – Field Processor

Processes text line‑by‑line using fields.

awk -F: '{print $1,$3}' /etc/passwd

Sum a column:

awk '{sum += $1} END{print sum}' numbers.txt

9. nano – Simple Text Editor

Keyboard‑friendly editor for quick edits.

nano /etc/hostname

Save with Ctrl+O, exit with Ctrl+X.

10. vim – Powerful Text Editor

Modal editor with extensive features.

vim /etc/hosts

Insert mode: i, save: :w, quit: :q, save & quit: :wq.

11. diff – Compare Files

Shows line‑by‑line differences.

diff old.txt new.txt

Unified format:

diff -u old.txt new.txt

12. comm – Compare Sorted Files

Requires sorted input; outputs three columns: unique to file1, unique to file2, common.

comm file1.txt file2.txt
comm -12 file1.txt file2.txt   # common lines only

Practice Session (Hands‑On)

Students will work in pairs to complete the exercises above. The instructor circulates to provide guidance and ensure that the “safety first” mindset is reinforced:

Assessment

  1. Quiz (5 min): 5 short‑answer questions covering command options and expected output.
  2. Mini‑Project (15 min): Students write a script that:
    1. Searches a directory for all .log files.
    2. Counts the number of error lines in each log using grep and wc -l.
    3. Outputs a summary file.
  3. Peer review of the script and commands used.

Resources & Further Reading

Feel free to adapt the schedule or exercises to suit your students’ skill level or time constraints.