Oct 22, 2026 · @Jim Skon
Read this before class. In class you will log in to our Ubuntu Linux server and do your programming there, so the goal is to arrive knowing what Linux is and how to type your first commands. Plan on about 45 minutes, and try the commands in the later sections as you read if you can.
Why Linux matters
Linux is the operating system most of the computing world quietly runs on, even though few people see it on a laptop.
- Servers and the cloud: most web servers and almost all cloud machines (Amazon, Google, Microsoft Azure) run Linux.
- Phones: Android is built on the Linux kernel.
- Supercomputers: every one of the world’s 500 fastest supercomputers runs Linux.
- Small devices: routers, smart TVs, cars, and the Raspberry Pi.
For a computer science student, Linux matters for three practical reasons. It is where your code will usually run after you graduate. Its command line lets you do in one line what takes many clicks, and lets you automate it. And it is open source, so you can read how an operating system actually works, including the data structures inside it.
A short history
Linux is a free, modern rebuild of Unix, an operating system from 1969 whose design ideas still shape almost every system you use.
| Year | What happened |
|---|---|
| 1969 | Ken Thompson and Dennis Ritchie create Unix at AT&T’s Bell Labs. |
| 1973 | Unix is rewritten in C, a language Ritchie designed, so it can be moved to new computers. |
| 1983 | Richard Stallman starts the GNU Project to build a completely free Unix-like system. |
| 1991 | Linus Torvalds, a student in Finland, announces a free kernel he wrote as a hobby: Linux. |
| 1992 | Linux is released under the GNU General Public License, so anyone may use, study, change and share it. |
| 1993 to 1994 | The first distributions, such as Debian and Red Hat, bundle Linux with GNU tools into installable systems. |
| 2004 | Ubuntu, based on Debian, is released, aiming to make Linux easy to install and use. |
| 2008 | The first Android phone ships, running on the Linux kernel. |
Two ideas from this history explain how Linux works today. First, Linux itself is only the kernel; the commands you type mostly come from the GNU Project, which is why some people say “GNU/Linux.” Second, a distribution (“distro”) is a kernel plus tools, a package manager and default settings. Our server runs Ubuntu, one of the most popular distributions.
How Linux is put together
Linux is built in layers: you talk to the shell, the shell starts programs, and programs ask the kernel to do anything that involves the hardware.
[embed: node/77958fad-a8d4]The layers above the system calls are user space. If one of your programs crashes there, only that program stops. The kernel runs in kernel space, where it manages every process, hands out memory, keeps files organized, and checks permissions. When your C++ program calls cout, the library underneath eventually makes a write system call, and the kernel puts the characters on your screen.
Two more ideas tie the system together:
- Everything is a file. Documents, directories, and even devices such as the keyboard and disks appear as files, so the same commands work on all of them.
- One directory tree. There are no drive letters like
C:. Everything hangs off a single root directory, written/.
| Directory | What lives there |
|---|---|
/ | The root: the top of the whole tree |
/home | One folder per user. Yours is /home/yourusername, also written ~ |
/bin, /usr/bin | The programs behind commands like ls and g++ |
/etc | System settings, stored as text files |
/tmp | Temporary files, cleared on restart |
/dev | Devices, shown as files |
Linux is also multi-user: many people are logged in to our server at once, each with their own home directory and files. The administrator account is called root (not the same thing as the / directory). You will not have root access, which keeps the server safe for everyone.
Logging in to the class server
You will connect to the server over the network with ssh (secure shell), which gives you a command line on the server inside a window on your own computer. The server’s address is 10.192.145.179. Your username is your student username, and your starting password is your student ID.
- Open a terminal on your own computer.
- Mac: open the Terminal app (search for it with Spotlight, Command-Space).
- Windows 10 or 11: open PowerShell or Windows Terminal from the Start menu. The
sshcommand is built in. - Linux or ChromeOS with Linux enabled: open the Terminal app.
- Type the command below with your own username in place of yourusername, and press Enter:
ssh yourusername@10.192.145.179
- The first time, ssh asks whether you trust the server (“Are you sure you want to continue connecting?”). Type
yes. - Type your password, which starts out as your student ID. Nothing appears as you type, not even dots. That is normal; type it and press Enter.
- If it worked, you see a welcome message and a prompt like
yourusername@servername:~$. You are now typing commands on the server. - Your student ID is not a secret, so change your password right away with
passwd. It asks for the old password once and the new one twice. - When you are done, type
exit(or press Control-D) to log out.
If you see Permission denied, check the spelling of your username and retype the password slowly. An address starting with 10. works only inside the campus network. If the connection times out off campus, connect to the college VPN first.
Finding your way around
The shell always has a current directory, the folder you are “in.” Most commands work on files there unless you say otherwise.
The prompt yourusername@servername:~$ tells you who you are, which machine you are on, and where you are: ~ means your home directory. A command is a name followed by options and arguments, separated by spaces:
ls -l /home
Here ls is the command, -l is an option (“long format”), and /home is the argument (what to list). Linux is case sensitive, so ls, LS and Ls are different.
| Command | What it does | Example |
|---|---|---|
pwd | Print the working (current) directory | pwd shows /home/yourusername |
ls | List the files here | ls -l adds sizes, dates and permissions; ls -a shows hidden files |
cd dir | Change into a directory | cd projects |
cd .. | Go up one level, to the parent directory | cd ../.. goes up two |
cd or cd ~ | Go back to your home directory | |
clear | Clear the screen | Control-L does the same |
Absolute and relative paths. A path that starts with / is absolute: it starts from the root, like /home/yourusername/lab1. Any other path is relative to where you are now. From your home directory, lab1 and /home/yourusername/lab1 name the same folder. Two special names work everywhere: . means “this directory” and .. means “the parent directory.”
Three habits will save you a lot of typing:
- Tab completion: type the start of a file or command name and press Tab. The shell finishes it, or press Tab twice to see the choices.
- History: press the Up arrow to bring back earlier commands.
historylists them. - Stop a program: press Control-C to stop a program that is stuck or running too long.
Working with files and directories
A handful of commands create, copy, move, delete and display files. Each one is short to type, and each one does exactly what you tell it, with no undo.
| Command | What it does | Example |
|---|---|---|
mkdir name | Make a new directory | mkdir lab1 |
touch file | Create an empty file, or update an existing file’s date | touch notes.txt |
cp from to | Copy a file | cp main.cpp backup.cpp |
cp -r from to | Copy a directory and everything in it | cp -r lab1 lab1-copy |
mv from to | Move a file, or rename it | mv backup.cpp old/ or mv a.txt b.txt |
rm file | Delete a file | rm backup.cpp |
rm -r dir | Delete a directory and everything in it | rm -r lab1-copy |
rmdir dir | Delete an empty directory | rmdir old |
cat file | Print a whole file to the screen | cat notes.txt |
less file | Page through a long file: Space for the next page, q to quit | less main.cpp |
head file / tail file | Show the first or last 10 lines | tail -n 20 output.txt |
wc file | Count lines, words and characters | wc -l main.cpp |
There is no trash can. rm deletes a file for good, and rm -r deletes a whole folder without asking. Double-check the name before you press Enter, and use rm -i if you want it to ask first.
Wildcards let one command match many files. * matches any characters and ? matches exactly one:
ls *.cpp # every file ending in .cpp cp *.h backup/ # copy all header files into backup rm test?.txt # test1.txt, test2.txt, ... but not test10.txt
File names may contain spaces, but they make commands harder to type. Use dashes or underscores instead, like lab-1 or linked_list.cpp. A name that starts with a dot, like .bashrc, is hidden from plain ls.
Help, permissions, pipes and processes
Getting help. Every standard command has a manual page. man ls opens it (Space to page, /word to search, q to quit). Most commands also print a short summary with --help, as in ls --help.
Permissions. Every file has an owner, and permission to read, write and execute it, set separately for the owner, the owner’s group, and everyone else. ls -l shows them at the start of each line:
-rwxr-x--- 1 yourusername students 16840 Oct 22 10:15 lab1
Read it as one type character (- for a file, d for a directory), then three sets of three: the owner can read, write and run lab1; the group can read and run it; everyone else can do nothing. Change permissions with chmod. For example, chmod go-rwx lab1 removes all access for the group and others, which keeps your homework private. You will usually not need to change anything else.
Pipes and redirection. Programs read input and write output as streams of text, so you can connect them:
| Symbol | What it does | Example |
|---|---|---|
> | Send output into a file, replacing what was there | ls > files.txt |
>> | Add output to the end of a file | echo done >> log.txt |
< | Read input from a file instead of the keyboard | ./lab1 < input.txt |
| | Pipe: send one program’s output into the next one | ls -l | less |
The < form is especially useful for testing: put your test input in a file once, then run your program on it as often as you like. grep finds lines that contain a word, so grep -n "main" *.cpp shows every line, with its line number, that mentions main.
Processes. Every running program is a process with an ID number. ps lists yours, and top shows everything running on the server, live (q to quit). Control-C stops the program in front of you. If one of your programs runs away in the background, kill followed by its process ID stops it. Because the server is shared, please stop programs you no longer need.
Writing and running C++ on the server
The whole edit, compile, run cycle happens at the command line: nano to write the code, g++ to compile it, and ./ to run it.
Edit with nano. nano hello.cpp opens the file (or creates it). Type normally and use the arrow keys to move. The commands are listed at the bottom of the screen, where ^ means the Control key:
- Control-O, then Enter: save (“write Out”)
- Control-X: exit
- Control-K / Control-U: cut a line / paste it
- Control-W: search
Compile with g++. Try this complete example:
mkdir hello cd hello nano hello.cpp # type the program below, save, exit g++ -Wall -o hello hello.cpp ./hello
#include <iostream>
using namespace std;
int main() {
cout << "Hello from Linux!" << endl;
return 0;
}g++ -Wall -o hello hello.cpp compiles hello.cpp, turns on all warnings (-Wall), and names the program hello (-o hello). If the compiler finds an error, it prints the file name and line number, such as hello.cpp:5:5: error: .... Fix that line in nano and compile again.
Run it with ./. The shell only looks for programs in the system directories, not in your current folder, so you must say where it is: ./hello means “the program hello in this directory.”
make. Bigger projects come with a Makefile that holds the compile commands. Typing make in that directory rebuilds whatever has changed, and make clean deletes the compiled files.
Before class
Try these on the server before class. If any step fails, note the exact error message and bring it.
- Log in with
ssh yourusername@10.192.145.179 - Change your password with
passwd - Run
pwd, thenls -la, and find your hidden files - Make a directory called
linux-practiceandcdinto it - Create
hello.cppin nano, compile it with g++, and run it - Copy it to
hello2.cpp, rename the copy tohi.cpp, then delete it - Run
ls -l > files.txtand look at the result withcat files.txt - Open
man lsand find what the-toption does - Log out with
exit
Cheat sheet
| Task | Command |
|---|---|
| Where am I? | pwd |
| What is here? | ls -la |
| Go into a folder / up one / home | cd name / cd .. / cd |
| New folder / empty file | mkdir name / touch file |
| Copy / move or rename / delete | cp a b / mv a b / rm file |
| Show a file | cat file or less file |
| Edit a file | nano file |
| Compile and run | g++ -Wall -o prog prog.cpp then ./prog |
| Run with test input | ./prog < input.txt |
| Search inside files | grep -n word *.cpp |
| Manual page | man command |
| Stop a program | Control-C |
| Finish a name / repeat a command | Tab / Up arrow |
| Log out | exit |
Further reading
These are free and worth bookmarking if you want more practice:
- The Linux command line for beginners: Ubuntu’s own step-by-step tutorial, about an hour.
- The Linux Command Line by William Shotts: a complete free book, from first commands to shell scripts.
- The Missing Semester: The Shell: MIT’s lecture and notes on using the shell well, with exercises.
- GNU nano: the editor’s home page and documentation.
