UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 1.7 Free with a free account
The Command Line
Introduction to Operating Systems · Chapter 1: Operating System FoundationsSection 1.7 · lesson 7 of 838 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Batch Files and Scripts →← Mobile Operating SystemsNext lesson: Batch Files and Scripts →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
Typing shell commands to move around, write files, and join tools.
- Explain the roles of the shell, the terminal, and the prompt
- Navigate a file tree with absolute and relative paths using cd, pwd, and ls
- Use one and two greater-than signs to replace or append file contents
- Combine grep, wc, sort, and uniq with pipes and read exit codes
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,075 words). Read along, or search it.
Opening Question
A Hundred Machines Checked by Typing
Ivy looks after the computers at a school, and she often works without touching the mouse at all. She types a few words, presses Enter, and a hundred lab machines are checked, in the time it takes to open one folder window. To a beginner, it looks like a movie hacker's screen. To Ivy, it's just a very polite, very literal way of asking the operating system to do things. By the end of this lesson, you'll be doing it too.
Key Terms
CLI, Shell, Terminal, and Prompt
A graphical interface shows you pictures to point at. A command line interface, or CLI, lets you type instructions instead. Same OS, same work: only the way you ask changes. The program that reads what you type, and carries it out, is called a shell, since it wraps around the kernel like a shell around a nut. The window that holds the typing is the terminal. And the prompt, often a dollar sign, is the shell saying: I'm ready. Most Linux systems use a shell called bash. A Mac starts new accounts in zsh, but bash is installed too, and every command in this lesson is real bash, run on a Mac.
Why Type
Repeat, Save, Share, and Combine
Why bother, when a GUI exists? Typed commands can be repeated, saved, shared, and joined together. A server in a closet has no screen at all. And a single typed line can do to a thousand files what would take a thousand clicks.
File Tree
Root, Working Directory, and Paths
Files live in a file tree: folders, also called directories, inside folders, all growing from one starting point, called the root, written as a single slash. On a Mac, people's own files live under slash Users. Sam, who runs a small online bakery, might keep his in slash Users, slash sam, slash bakery. At any moment, the shell is standing in one folder: the working directory. A path that starts with a slash is absolute: it starts at the root. Any other path is relative: it starts where you're standing. Two shortcuts help. A single dot means here, and two dots mean the folder above.
Moving Around
Changing Folders and Checking Location
Let's try it. cd, short for change directory, moves the shell. Go to slash usr slash share: an absolute path. pwd, print working directory, says where you are: slash usr slash share. Now cd dot dot climbs one folder up. pwd again: slash usr. ls lists what's in this folder. These are folders the system keeps in slash usr, and share is one of them. And cd share uses a relative path. Share is right here, so the shell steps down into it, and pwd confirms it.
Making Files
Writing Files With Echo and Cat
cd on its own goes home, to your own folder. Make a new folder with mkdir bakery, and cd into it. echo prints words. With one greater-than sign, the words go into a file instead of the screen, creating it. Two greater-than signs add a line to the end of a file. So now orders dot t x t holds two orders. ls lists the folder, and cat shows a file's contents: both orders, in order.
Common Mistake
One Greater-Than Sign Erases a File
The classic mistake is one greater-than sign when you meant two. Watch: echo three cupcakes, with a single sign. Now cat the file again. The muffins and the cake are gone. A single sign replaced everything that was in the file.
Quick Check
Scones, Pies, and Redirection
Quick check. The file now holds just the cupcakes. Sam types two more lines: echo four scones, with two signs, then echo five pies, with one sign. What does cat orders dot t x t print now? Pause and predict. Only five pies. The double sign added the scones, but then the single sign replaced the whole file, scones and cupcakes included. When you mean to add, use two signs. They never throw anything away.
Small Tools
Small Tools Joined by Pipes
Next, small tools. Sam keeps a file of what sold today, one item per line. grep keeps only the lines that contain a word. wc dash l counts lines. sort puts lines in order, and uniq dash c counts repeats. Their power comes from the pipe, the vertical bar. It feeds the output of one command straight into the next, like a conveyor belt between kitchen stations.
Worked Example
Counting Muffins and Top Sellers
First, cd dot dot, back up to the home folder, where the sales file is. How many muffins went out today? grep muffin sales dot t x t keeps the three muffin lines. Pipe them into wc dash l, and it counts them: three. And which item sells most? Sort the file, and pipe it into uniq dash c: one bagel, two cakes, three muffins.
Quick Check
Counting Repeats Without Sorting
Quick check. Sam drops sort, and runs uniq dash c straight on the file. What does it print? Pause and predict. Six lines, each counted once. uniq only notices repeats that sit right next to each other. In this file, no two equal lines are neighbors, so every line is a run of one. That's why sort comes first: it brings the equal lines together.
Exit Codes
Zero Means Success
Last idea: what happens when a command fails? Ask for a folder that doesn't exist: ls cupcakes. The shell doesn't crash. ls prints a clear message, no such file or directory, and carries on. Every command also leaves an exit code, and dollar question mark holds the last one. Here, it's one. Try one that works: ls sales dot t x t. Now the exit code is zero. Zero means success, and anything else means a problem. On Linux, ls reports two for that missing folder. The number differs, but the meaning is the same: not zero, so something went wrong.
Real Example
Counting Overnight Errors
Back to Ivy. One morning she needed to know how many lab machines had reported an error overnight. She ran the night's log through grep error and wc dash l, just like Sam's muffin count, and had her answer in a second. I didn't write a program, she said. I snapped two small tools together.
Key Takeaways
Shell, Paths, Redirection, and Pipes
To recap. The shell reads your commands, the terminal holds them, and the prompt says it's ready. pwd, cd, ls and mkdir move you around the tree, with absolute or relative paths. One greater-than sign replaces a file, and two add to it. Pipes join small tools, and an exit code of zero means success.
Try It
A First Session in Terminal
Here's something to try. Open Terminal on a Mac, or PowerShell on Windows, where some names differ. Make a folder, move into it, write two lines with echo, and read them back with cat. Press Tab to finish names, and the up arrow to repeat a command.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About The Command Line
What is the difference between a shell and a terminal?
What is the difference between an absolute path and a relative path?
What is the difference between > and >> in the shell?
What does the pipe symbol do on the command line?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →