Introduction to Linux

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.

YearWhat happened
1969Ken Thompson and Dennis Ritchie create Unix at AT&T’s Bell Labs.
1973Unix is rewritten in C, a language Ritchie designed, so it can be moved to new computers.
1983Richard Stallman starts the GNU Project to build a completely free Unix-like system.
1991Linus Torvalds, a student in Finland, announces a free kernel he wrote as a hobby: Linux.
1992Linux is released under the GNU General Public License, so anyone may use, study, change and share it.
1993 to 1994The first distributions, such as Debian and Red Hat, bundle Linux with GNU tools into installable systems.
2004Ubuntu, based on Debian, is released, aiming to make Linux easy to install and use.
2008The 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 /.
DirectoryWhat lives there
/The root: the top of the whole tree
/homeOne folder per user. Yours is /home/yourusername, also written ~
/bin, /usr/binThe programs behind commands like ls and g++
/etcSystem settings, stored as text files
/tmpTemporary files, cleared on restart
/devDevices, 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.

  1. 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 ssh command is built in.
    • Linux or ChromeOS with Linux enabled: open the Terminal app.
  2. Type the command below with your own username in place of yourusername, and press Enter:
ssh yourusername@10.192.145.179
  1. The first time, ssh asks whether you trust the server (“Are you sure you want to continue connecting?”). Type yes.
  2. 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.
  3. If it worked, you see a welcome message and a prompt like yourusername@servername:~$. You are now typing commands on the server.
  4. 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.
  5. 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.

CommandWhat it doesExample
pwdPrint the working (current) directorypwd shows /home/yourusername
lsList the files herels -l adds sizes, dates and permissions; ls -a shows hidden files
cd dirChange into a directorycd projects
cd ..Go up one level, to the parent directorycd ../.. goes up two
cd or cd ~Go back to your home directory
clearClear the screenControl-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. history lists 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.

CommandWhat it doesExample
mkdir nameMake a new directorymkdir lab1
touch fileCreate an empty file, or update an existing file’s datetouch notes.txt
cp from toCopy a filecp main.cpp backup.cpp
cp -r from toCopy a directory and everything in itcp -r lab1 lab1-copy
mv from toMove a file, or rename itmv backup.cpp old/ or mv a.txt b.txt
rm fileDelete a filerm backup.cpp
rm -r dirDelete a directory and everything in itrm -r lab1-copy
rmdir dirDelete an empty directoryrmdir old
cat filePrint a whole file to the screencat notes.txt
less filePage through a long file: Space for the next page, q to quitless main.cpp
head file / tail fileShow the first or last 10 linestail -n 20 output.txt
wc fileCount lines, words and characterswc -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:

SymbolWhat it doesExample
>Send output into a file, replacing what was therels > files.txt
>>Add output to the end of a fileecho done >> log.txt
<Read input from a file instead of the keyboard./lab1 < input.txt
|Pipe: send one program’s output into the next onels -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, then ls -la, and find your hidden files
  • Make a directory called linux-practice and cd into it
  • Create hello.cpp in nano, compile it with g++, and run it
  • Copy it to hello2.cpp, rename the copy to hi.cpp, then delete it
  • Run ls -l > files.txt and look at the result with cat files.txt
  • Open man ls and find what the -t option does
  • Log out with exit

Cheat sheet

TaskCommand
Where am I?pwd
What is here?ls -la
Go into a folder / up one / homecd name / cd .. / cd
New folder / empty filemkdir name / touch file
Copy / move or rename / deletecp a b / mv a b / rm file
Show a filecat file or less file
Edit a filenano file
Compile and rung++ -Wall -o prog prog.cpp then ./prog
Run with test input./prog < input.txt
Search inside filesgrep -n word *.cpp
Manual pageman command
Stop a programControl-C
Finish a name / repeat a commandTab / Up arrow
Log outexit

Further reading

These are free and worth bookmarking if you want more practice:

Scroll to Top