Lecture notes · The Missing Semester · Lecture 2

Shell Tools and Scripting

MIT 6.NULL The Missing Semester of Your CS Education, lecture 2, explained in plain English

Want this lecture to stick? In LessonBound you get checked practice questions for every part, can ask about anything you don't get, and can listen with your screen off. Free, no ads.

Learn this lecture free

Watch or read the original lecture: MIT OpenCourseWare.

Part 1

This part introduces bash shell scripting, the basic building blocks of variables, quotes, exit codes, and scripts versus functions.

Key ideas

Words to know

Exit code
A number a command gives back when it finishes, to say whether it worked. Zero means success and anything else means something went wrong.
Command substitution
Running a command inside $( ) so its printed output is put into the spot where the command was written.
Shebang line
The first line of a script that starts with #! and names the program that should run the script, such as python.
Shell globbing
Using wildcard characters like ? and * in a file name so the shell fills in all the matching file names for you.

Example

Think of a wildcard like a search pattern for file names. If a folder holds files named foo, foo1, foo2, foo10, and bar, then the command rm foo? removes only foo1 and foo2, because ? matches exactly one character. The shell does the matching before the command runs.

3 checked practice questions for this part are in the app.

Part 2

This part teaches how to find files, find text inside files, find old commands, and move between folders quickly from the command line.

Key ideas

Words to know

recursively
going into every folder inside a folder, and then into the folders inside those, all the way down.
manpage
a built-in instruction manual for a command, opened with the man command.
frecency
a score that mixes how often you use a folder with how recently you used it.
cron
a scheduler that runs a task automatically at set times, such as once a day.

Example

Think of find as walking through every shelf of a library to look for a book, which takes time but is always up to date. The locate tool is like checking the library's card catalog, which is quick but may be a day old if new books were added since it was last updated.

3 checked practice questions for this part are in the app.

Part 3

This part gives you practice tasks for listing files, saving a directory shortcut, retrying a flaky command, and zipping files found by search, all from the command line.

Key ideas

Words to know

xargs
A command that reads items from input and hands them to another command as if you had typed them as arguments.
STDIN
The standard input stream, the place a command reads its input from. In a pipe, the output of one command flows into the STDIN of the next.
source
A command that loads a file's contents into your current shell, so the functions and settings in it become available right away.
recursively
Working through a folder and every folder inside it, all the way down, not just the top level.

Example

Think of xargs like a helper who receives a written list of items and then carries them to a worker one at a time. The worker only needs the items, not the list itself. This is how xargs turns a stream of file names into arguments that a command like tar can use.

3 checked practice questions for this part are in the app.

← Lecture 1: Course Overview + The Shell · Lecture 3: Editors (Vim) →

Notes written by AI (Claude) from the lecture's official transcript, so check anything important against the lecture. MIT CSAIL · CC BY-NC-SA 4.0 · not affiliated with or endorsed by MIT. These notes are shared under the same license.

LessonBound · Free lecture notes · Privacy · Terms · New York