=================================================================== UC CARPENTRIES · THE UNIX SHELL · Wed Sep 9, 2026 · 9:00-12:00 PT =================================================================== SETUP -- do both of these BEFORE we start ------------------------------------------------------------------- 1. A SHELL: - Mac / Linux: you already have one (Terminal). Mac: Cmd-Space, type "terminal", Enter. - Windows: install Git for Windows ("Git Bash"): https://gitforwindows.org Then: Start menu, type "git bash", Enter. (Not Command Prompt / PowerShell.) - Full setup + how to open a shell: https://swcarpentry.github.io/shell-novice/#setup 2. THE DATA: - Download: https://swcarpentry.github.io/shell-novice/data/shell-lesson-data.zip - Save it to your DESKTOP, then unzip it THERE. - You should end up with a folder called shell-lesson-data containing exercise-data and north-pacific-gyre Check it works -- open your shell and type: whoami cd ~/Desktop/shell-lesson-data ls -> exercise-data north-pacific-gyre Slides: https://www.tim-dennis.com/2026-09-08-uc-carpentries/slides/shell/ Notes: https://www.tim-dennis.com/2026-09-08-uc-carpentries/shell-notes/ Lesson: https://swcarpentry.github.io/shell-novice/ (we do Episodes 1-6 today) HOW THIS WORKS - ADD YOUR OS TO YOUR ZOOM NAME -- "Sam (Mac)" / "Sam (Windows)". It lets helpers see which setup instructions apply to you. - Work in your OWN terminal the whole time. An instructor drives one on screen. - We never type the "$" -- that's the prompt. Just type what comes after it. - Two instructors today, split in two halves with a break in each half. - Ctrl-C stops a command that's running away. In "man", press q to get out. - Done / stuck: use the Zoom reaction icons ( check / x ), or type a line here. - Put questions HERE in the pad, not only in chat -- helpers watch both. - "I'm stuck" is a complete sentence. WHO'S HERE (add yourself: name -- role, institution) - Tim Dennis -- instructor, UCLA Library Data Science Center - James Frew -- instructor ------------------------------------------------------------------- TODAY (Episodes 1-6) ------------------------------------------------------------------- Challenges are in the flow, where we hit them. Each is short and timed -- an instructor calls time and shows the answer. Put your answer under your name. [SLIDE n] marks when the instructor puts a diagram on screen -- deck is 10 slides: https://www.tim-dennis.com/2026-09-08-uc-carpentries/slides/shell/ ================================================================= PART 1 (Ep 1-3) ================================================================= 1. Open your shell. Why the shell: do one thing to 400 files (Nelle's 1520 files) [SLIDE 2] "Open a shell" (Mac Spotlight / Windows Git Bash) [SLIDE 3] "Get to the prompt" [SLIDE 4] "Why the command line?" [SLIDE 5] "Why type when you can click?" 2. Navigating: pwd, ls and its options, man / --help [SLIDE 6] "The filesystem is a tree" 3. Moving around: cd, .. , cd alone, cd - , absolute vs relative paths, ~ ------------------------------------------------------------- CHALLENGE C1 -- Absolute vs Relative Paths (~3 min) ------------------------------------------------------------- Starting from /Users/nelle/data , which of these commands could Nelle use to get to her home directory, /Users/nelle ? (more than one works) 1. cd . 4. cd ../.. 7. cd ~/data/.. 2. cd / 5. cd ~ 8. cd 3. cd /home/nelle 6. cd home 9. cd .. - name: - name: ------------------------------------------------------------- CHALLENGE C2 -- Listing in Reverse Chronological Order (~2 min) ------------------------------------------------------------- ls -t lists items by time of last change instead of by name. ls -r lists them in reverse order. Combine them ( ls -t -r ; add -l to see the dates ) -- which file is displayed LAST? - name: - name: *** break *** 4. Command shape: command / option / argument [SLIDE 7] "The shape of a command" 5. Making things: nano (a text file), mkdir 6. mv (rename / move), cp (copy, -r for folders), rm (NO UNDO) ------------------------------------------------------------- CHALLENGE C3 -- Renaming Files (~1 min) ------------------------------------------------------------- You made a file and named it statstics.txt -- you meant statistics.txt . Which command fixes the name? 1. cp statstics.txt statistics.txt 3. mv statstics.txt . 2. mv statstics.txt statistics.txt 4. cp statstics.txt . - name: - name: 7. Wildcards: * and ? ------------------------------------------------------------- CHALLENGE C4 -- List Filenames Matching a Pattern (~3 min) ------------------------------------------------------------- Run in the alkanes directory, which ls command(s) produce exactly this output: ethane.pdb methane.pdb 1. ls *t*ane.pdb 3. ls *t??ne.pdb 2. ls *t?ne.* 4. ls ethane.* - name: - name: *** handoff to Instructor 2 *** ================================================================= PART 2 (Ep 4-6) ================================================================= 8. Counting: wc, wc -l ; redirect > and >> 9. sort / sort -n , head , tail 10. The pipe | -- build: wc -l *.pdb | sort -n | head -n 1 [SLIDE 8] "Redirect, and the pipe" -- exercise: find the 3 shortest files ; cut | sort | uniq *** break *** 11. Loops: for ... in ... ; do ... ; done (creatures/*.dat) [SLIDE 9] "Loops: do it to the whole list" -- echo in front = a safe "dry run" -- exercise: trace a loop 12. Shell scripts: save a pipeline as sorted.sh , run with bash sorted.sh -- make it reusable with "$@" [SLIDE 10] "Recap" (keypoints) ------------------------------------------------------------------- COMMANDS -- QUICK REFERENCE ------------------------------------------------------------------- whoami ................. what user am I pwd ..................... where am I ls / ls -F / ls -l / ls -lh / ls -a ... list / mark types / long / human sizes / all man CMD / CMD --help .. how to use a command (in man: q to quit) cd DIR / cd .. / cd / cd - ... into / up one / home / previous directory . = here .. = one level up ~ = home / = root nano FILE .............. edit a text file (Ctrl-O then Enter = save, Ctrl-X = exit) mkdir NAME / mkdir -p a/b/c ... make a directory / make nested directories mv OLD NEW ............. rename, or move into a directory cp OLD NEW / cp -r DIR NEWDIR ... copy a file / copy a whole directory rm FILE / rm -r DIR .. DELETE. no Trash, no undo. -i to be asked first. * ? ................. wildcards: any characters / exactly one character wc / wc -l / wc -w ..... count lines+words+chars / lines / words sort / sort -n ...... alphabetical / numerical order head -n N / tail -n N ... first N lines / last N lines cut -d , -f 2 FILE .... pull out column 2 (comma-separated) uniq / uniq -c ...... drop adjacent duplicate lines / count them (sort first!) > >> | ............ write to file (overwrites!) / append / pipe to next command Ctrl-C ............... stop a running command up-arrow = recall last command LOOP TEMPLATE for filename in *.dat do echo $filename head -n 2 $filename | tail -n 1 done ( put "echo" in front of a command to preview what the loop would do ) SCRIPT nano sorted.sh # then type: # Sort files by their length. wc -l "$@" | sort -n bash sorted.sh *.pdb bash sorted.sh ../creatures/*.dat ------------------------------------------------------------------- NOTES (everyone: edit these as we go) ------------------------------------------------------------------- ------------------------------------------------------------------- QUESTIONS (drop them here) ------------------------------------------------------------------- ------------------------------------------------------------------- FEEDBACK (one thing that worked / one thing to change) -------------------------------------------------------------------