CSC60 Week 1 Notes

Instructor Introduction

  • Mark Ainsley, CSUS graduate with ~30 years of software experience across IT, Software QA, Software Development, Software Leadership (roles include Software QA, Software Engineer, Lead Engineer, Manager, Director).
  • Course: CSC60 – Intro to System Programming Unix (Spring 25, Week 1). Motto: "Whether you think you can or think you can’t – you are right." – Henry Ford

Course Description

  • Hands-on approach to learn features of the C language commonly used in systems programming and its application in a UNIX environment.
  • Topics include:
    • C preprocessor macros
    • File I/O
    • Bit-manipulation facilities
    • Timesharing system concepts
    • File permissions
    • Shell script programming
    • Building C programs via make files
    • Basic system calls like fork and exec
    • Pointers and dynamic memory allocation
    • Libraries and relocation and linking concepts including assembler handling of symbol tables
  • Prior knowledge assumed: familiarity with a C-like language (Java, C++, C#, Python, …)
  • Prerequisites: CSC 20, CSC 35

Week 1 – Assignments

  • Reading:
    • DigitalOcean – An Introduction to Linux Basics
    • Linux Foundation – Vim 101: A Beginner's Guide to Vim
  • Lab:
    • Lab 1 – Intro to Linux and Vim
  • Note: Details available on Canvas Assignment for Week 1

Week 1 External References

  • Course References:
    • Jacob Sorber Video Series
    • CodeVault Video Series
  • Additional References for Week 1:
    • Medium – Linux Architecture
    • Technopedia – System Programming
    • YouTube – The Ultimate Beginner’s Guide to Learn and Master Vim
    • FreeCodeCamp – Vimrc Configuration Guide
    • MIT University – Vi Cheat Sheet (or longer reference sheet)

Syllabus Overview

  • Course Description (as above)
  • Textbook/External References
  • Homework/Labs
  • Quizzes: 33 quizzes, short and in-class
  • Tests: 11 midterm and 11 Final Exam
  • Midterm on Canvas, Final Exam in-class on paper

What We'll Learn (Course Scope)

  • Working in a Linux system and a lot of Linux commands
  • Linux shells: multiple shells exist (sh, csh, ksh, zsh, bash, …); default login shell on ECS systems is bash; on Mac it may be zsh
  • Linux architecture at a high level and how to navigate the Linux file system
  • Creating and editing text files using a native Linux editor, primarily vim (vi)
  • A broad view of Systems Programming concepts
  • Hands-on labs/exercises to practice all topics

Some Terminology

  • Unix: family of proprietary OSs developed in the 1970s at Bell Labs (license required)
  • Linux: free, open-source version of a Unix kernel developed by Linus Torvalds
  • Note: “Unix” and “Linux” are often used interchangeably in casual usage, but they are distinct
  • FTP: File Transfer Protocol (transferring files to/from systems)
  • SCP: Secure Copy Protocol (encrypted file transfers)
  • Putty: SSH client for Windows to connect to Linux systems
  • Terminal: Mac application to access the shell/CLI

Accessing Linux (Course Environment)

  • ECS Linux systems are used for coursework
    -Mac users can use macOS terminal for many activities; differences may exist between macOS and ECS Linux versions
  • Will log into Linux to compile/run C programs, and transfer files between local machine and ECS systems

Using ECS Linux Systems

  • To use ECS systems, login to a remote ECS system via a terminal
  • You will need to transfer files between your local system and the ECS system
  • VPN access via GlobalProtect is required for off-campus access
  • Coding systems to use:
    • ecs-pa-coding1.ecs.csus.edu
    • ecs-pa-coding2.ecs.csus.edu
    • ecs-pa-coding3.ecs.csus.edu

GlobalProtect VPN

  • GlobalProtect is a VPN client to access CSUS servers remotely
  • Install once; connect when:
    • You are on a non-campus computer, or
    • You are not connected to the campus network

MacOS Usage for this Course

  • MacOS is Unix-based and compatible with many activities in this course
  • To log in from Mac: open a Terminal window and run SSH to ECS coding systems (example below)
  • File transfers may be unnecessary if Canvas access provides required uploads

General ECS Linux Workflow

  • Steps to use ECS Linux systems:
    • Ensure GlobalProtect VPN is active if off-campus
    • Open a terminal and log into a Linux machine (e.g., via ssh)
    • Open an editor (vim is common for C projects)
    • Write/fix code, save, compile, and run the executable
    • Transfer files between local and ECS systems as needed for Canvas submissions
  • Keep track of multiple copies to identify the final version

Connecting Options (Remote Terminal & File Transfer)

  • Remote Terminal options:
    • Mac: Terminal app
    • Windows: Putty
    • Cross-platform: MobaxTerm
  • File transfer options:
    • Mac: scp command
    • Windows: WinSCP, Filezilla, Cyberduck

Remote Terminal – Mac Example

  • SSH into a coding system:
    • ssh @ecs-pa-coding1.ecs.csus.edu
  • Enter password when prompted

File Transfer – Mac (scp examples)

  • Copy file from Coding1 to Mac:
    • scp @ecs-pa-coding1.ecs.csus.edu:/foo.c .
  • Copy file from Mac to Coding1:
    • scp foo.c @ecs-pa-coding1.ecs.csus.edu:~
  • Note: ~ is shorthand for your home directory

Remote Terminal – Windows (Putty)

  • Steps:
    • Connect to GlobalProtect VPN
    • Open Putty and login to an ECS Coding Linux system
    • Saved sessions simplify reuse (font, color, window size, etc.)

Putty Login Screen (example details)

  • Address: ecs-pa-coding3.ecs.csus.edu
  • Connection Type: SSH
  • Save session (e.g., name it for easy access)
  • After saving, log in with the session name whenever needed

File Transfer – Windows (WinSCP)

  • WinSCP is a free tool for SFTP transfers between local and remote systems
  • Start: http://winscp.net/
  • Typical settings shown in class: SFTP protocol, host ecs-pa-coding1.ecs.csus.edu, user jimmy, port 22
  • You can save sessions for quick access

WinSCP Walkthrough (high level)

  • Left pane: local (your computer); Right pane: remote (Linux ECS)
  • Drag files between panes to transfer
  • Example session username: jimmy

Optional Home Software (Mac & Windows)

  • File transfer tools available: Filezilla, Cyberduck
  • Both support Windows and Mac; compare features if needed

Operating System Basics

  • An OS is a control program for a computer that:
    • Allocates resources
    • Schedules tasks
    • Provides a platform for applications
    • Interfaces between user and computer

OS Layers

  • OS typically built in layers; kernel at the core interacts with hardware via device drivers
  • Above the kernel: system utilities/commands including shells
  • Users interact with the system via the shell

The Shell – User Interface to the OS

  • Shell: command interpreter; interface between user/program and OS
  • Several shells exist: sh, csh, ksh, zsh, bash, …
  • Default login shell on ECS systems is bash; on Mac it may be zsh
  • Different shells offer different features (e.g., command history in bash)

The Kernel – Heart of the OS

  • Interacts with hardware via device drivers
  • Provides services to programs, insulating them from hardware
  • Manages memory, access control, filesystem, interrupts, resource allocation
  • Programs interact with kernel via system calls

System Programming Overview

  • System Programming targets building software that provides services to other software (often closer to hardware)
  • System Programs typically interact with hardware and require deeper understanding of the system
  • Often written in lower-level languages (e.g., C, Assembly)
  • System calls implemented in C to access system devices

Introduction to Linux (Key Components)

  • File/Directory Structure
  • The Shell(s)
  • Man Pages
  • Editor(s)
  • Libraries
  • Useful Linux commands
  • The C compiler
  • Note: Linux consists of many components beyond the kernel; GNU tools supply the rest

Unix History and POSIX

  • UNIX origins: Bell Labs; early machine-dependent programs
  • BSD Unix from UC Berkeley; System V standardization efforts by AT&T
  • The Linux kernel developed by Linus Torvalds; GNU project provides userland tools
  • POSIX (IEEE Portable Operating System Interface): defines a set of OS interfaces for applications to promote interoperability

Linux File Structure – All is a File Concept

  • In Linux, everything is treated as a file (text files, directories, devices, sockets, etc.)
  • This unifies input/output: you can read/write to files, sockets, or devices using the same approach

Linux File Structure – Example Directories

  • Root: /
  • Home directories: /home
  • User directories: /home/teachers, /home/students, etc.
  • Common substructure under user/home namespaces (e.g., /home/ainsleym, /home/smithj)
  • A Few Special Directories: Root, Home
  • Concepts: current directory, parent/child relationships, sub-directories, tree structure, path navigation

Man Pages – Getting Help in Linux

  • The phrase “Look at the man page” refers to online command documentation
  • Examples:
    • manextcommandman ext{command} (e.g., manlsman ls, mangccman gcc)
  • How to navigate a man page: space to advance, b to go back, Enter to advance line, k to go up, q to quit, h for help

Linux Commands (Common Utilities)

  • Commands to know (examples):
    • cat,cd,clear,cp,date/time,grep,ls,mkdir,more/less,ps,pwd,rm,rmdir,touch,uname,whocat, cd, clear, cp, date/time, grep, ls, mkdir, more/less, ps, pwd, rm, rmdir, touch, uname, who
  • Shell capabilities: interact with files, permissions, processes, etc.

Vi and Vim (Text Editor)

  • Vi is a line editor; Vim stands for Vi iMproved
  • Vim provides a large command set for movement and text manipulation; graphical Vi (gvim) also exists
  • On Mac, MacVim is available; graphical editors like VS Code, GNU Nano, Brackets can be used as well
  • Course focus: Vim for classwork

Using Vim – Basic Usage

  • To enter Vim: vimextYourFileNamevim ext{YourFileName} or viextYourFileNamevi ext{YourFileName}
  • Modes in Vim:
    • Command Mode: navigation and commands
    • Insert Mode: typing text
  • Entering Insert Mode: ii (insert before cursor); aa (insert after cursor); etc.
  • Exit Insert Mode: press EscEsc
  • Basic exit commands:
    • :q!:q! to quit without saving
    • :wq:wq to save and quit
    • :x:x or ZZZZ to save and quit (newer versions)
    • :q:q to quit if no changes pending
    • If no filename exists, use :wMyFile.txt:w MyFile.txt to save with a name

Vim – Basic Commands and Navigation

  • Enter Insert Mode: ii; Exit Insert Mode: EscEsc
  • Move within a file in Command Mode using:
    • Arrow keys or h (left), j (down), k (up), l (right) equivalents
    • Word movement: w or b (forward/back by word)
    • Line navigation: 0 (start of line), $ (end of line)
    • Paragraph navigation: { (start of previous paragraph), } (start of next paragraph)
  • Basic editing keys:
    • Delete: x (delete char under cursor), X (delete char before cursor)
    • Delete to end of line: D
    • Delete to end of word: dw
    • Delete to end of line from cursor: d$
    • Delete beginning of word to cursor: db
    • Delete current line: dd
    • Delete to end/beginning of paragraph: d{ / d}

Copy & Paste in Vim (Yank & Put)

  • Yanking (copy):
    • yy or Y: yank current line
    • y2w: yank two words to the right
    • 4yb: yank four words to the left
    • 3yy or 3Y: yank 3 lines
  • Pasting:
    • p: put after the cursor (lowercase)
    • P: put before the cursor (uppercase)
    • 5p: paste five times after cursor
  • Note: Yank = copy; Put = paste; Delete = cut

Initial List of Vim Commands to Learn (Summary)

  • Enter text: i (insert before cursor); o/O (open a line below/above and insert)
  • Exit insert mode: Esc
  • Movement in Command Mode: arrows; w/b, 0, $, /, 0, etc.
  • Deleting text: x, dw, d$, etc.
  • Modifying text: s (substitute); cw (change to end of word)
  • Misc: yy then p (cut and paste); u (undo); :wq (save and quit); :q! (force quit without saving)

Creating, Saving, Discarding, Quitting with Vim

  • Creating a file: viextfile.txtvi ext{ file.txt} opens file.txt (creates if not existing upon save)
  • Saving a file: :w:w (binds to file name if not yet given)
  • Discard changes and quit: :q!:q!
  • Save and quit: :wq:wq

Vim Settings and Configuration

  • Common settings:
    • setaiset ai: auto-indent
    • setnoaiset noai: turn off auto-indent
    • setnuset nu: show line numbers
    • setnonuset nonu: hide line numbers
    • setts=8set ts=8: tab stops at 8 characters
    • setsw=4set sw=4: shift width = 4 characters (for >>)
    • syntaxonsyntax on: enable syntax highlighting
  • Startup configuration: save settings in a file named ".vimrc" in your home directory
  • Comments in .vimrc start with a double quote ("")

Homework and Labs (Course Structure)

  • The topics are best learned through hands-on exercises
  • Each week includes:
    • Reading assignments
    • Lab exercises on Canvas due before the next week's class
  • Reading assignments reinforce class topics; lab points may count toward quizzes and tests

Practical Takeaways for Week 1

  • You will work with Linux systems via ECS coding machines
  • Use VPN (GlobalProtect) for off-campus access
  • Learn and practice Vim as your primary editor for C development in this course
  • Familiarize yourself with Linux basics, file system navigation, and man pages as primary help resources
  • Expect a mix of short in-class quizzes and longer assignments (labs) to assess practical skills
  • Understand the layered nature of OSes: kernel, shells, user space, and the role of system calls
  • Begin to explore connecting and transferring files between local machines and ECS via ssh, scp, Putty, WinSCP, FileZilla, Cyberduck
  • Keep in mind the historical context of Unix/Linux and POSIX standards for portability and interoperability