Your first Linux commands
The terminal is a window where you type instructions instead of clicking. It looks unfriendly, but it’s only a conversation: you type a command, the computer replies, and it waits for the next one. In this lesson you’ll get a Linux terminal on the computer you already own and run your first commands. Nothing here can damage anything.
In this lesson
- Get a working terminal on Windows, Mac or Linux
- Read the prompt and run your first commands
- Use the keys that save time and get you out of trouble
You’ll need: a Windows, Mac or Linux computer. A phone won’t do for this course. On Windows you’ll install a free Microsoft feature, which needs an administrator account and one restart.
Why bother with Linux?
Linux runs a large share of the world’s web servers, and Android phones and many home routers are built on it too. Once you can use its command line, you can look after a website, a home server or a Raspberry Pi, and you can do repetitive jobs in seconds. It’s also the fastest way to understand what a computer is really doing, because very little is hidden behind buttons.
A few words you’ll see: the terminal is the window, and the shell is the program inside it that reads what you type. On most Linux systems the shell is called Bash.
Try it yourself ยท part 1
Get a terminal
๐ช Windows
Windows has a free feature that runs real Linux inside it, called the Windows Subsystem for Linux (WSL). It needs Windows 10 version 2004 or later, or Windows 11.
- Press Windows, type
PowerShell, right-click it and choose Run as administrator. - Run this command, then restart your computer when it finishes:
wsl --install- Press Windows, type
Ubuntuand open it. The first launch takes a moment while it unpacks. - Choose a user name and a password. They’re only for Linux and don’t have to match your Windows ones. Nothing may appear on screen as you type the password, which is normal.
If the install stops with an error about virtualisation, or it’s a work computer that blocks it, see Microsoft’s troubleshooting page.
๐ Mac
Press Cmd + Space, type Terminal and press Enter. There’s nothing to install. Macs use a shell called zsh rather than Bash, and macOS isn’t Linux, but nearly every command in this course works the same. Where one doesn’t, the lesson says so.
๐ง Linux
Search your apps for Terminal. On Ubuntu and many others, Ctrl + Alt + T opens it too.
Read the prompt
The text waiting at the start of the line is the prompt. It tells you who and where you are, and that the computer is ready:
sam@laptop:~$| Part | What it means |
|---|---|
| sam | The user you’re logged in as |
| laptop | The name of this computer |
| ~ | Where you are: ~ is short for your home folder |
| $ | Ready for a command, as a normal user |
On a Mac it looks more like sam@MacBook ~ %. Same information, different punctuation. When a page shows a command to type, you never type the prompt itself.
Try it yourself ยท part 2
Run your first commands
- Type each of these and press Enter. Who are you?
whoami - Where are you?
pwd - What’s the date, according to this computer?
date - Make it say something back:
echo Hello from the terminal - What’s in this folder? On a new Ubuntu install, the answer is probably nothing, and the command prints nothing. Silence usually means success.
ls - Now get it wrong on purpose, with capitals:You’ll get
LScommand not found, perhaps with a suggestion. Linux treats capitals and small letters as different, solsandLSare two different things. On a Mac this exact mistake may still work, because of how its disk is set up, but don’t rely on it.
Your first few commands should look something like this, with your own name and path:
sam@laptop:~$ whoami
sam
sam@laptop:~$ pwd
/home/sam
sam@laptop:~$ echo Hello from the terminal
Hello from the terminalThe shape of every command
Almost every command has the same three parts: what to do, how to do it, and what to do it to.
ls -l /etc| Part | Example | What it does |
|---|---|---|
| Command | ls | The program to run: list files |
| Option | -l | Changes how it behaves: show a long, detailed list |
| Argument | /etc | What to work on: the folder called /etc |
Every command comes with a manual. Run man ls, move with the arrow keys, and press q to quit. Manual pages are dense, so don’t try to read them from top to bottom: look for the one option you need.
The keys that save you
| Key | What it does |
|---|---|
| Tab | Finishes a command or file name for you. Press it constantly: it saves typing and prevents mistakes |
| โ | Brings back your previous commands, so you can run or fix them |
| Ctrl + C | Stops whatever is running and gives you a fresh prompt. It doesn’t copy here |
| Ctrl + L | Clears the screen. clear does the same |
Try it yourself ยท part 3
Stop a command that won’t stop
- On Linux and Mac,
pingkeeps going until you stop it. Start it:ping examineip.com - Watch a few replies arrive, then press Ctrl + C. It stops and prints a summary. If you’re ever stuck, or the prompt has turned into a
>, this is the key to try first. - Press โ to see the command again, then Ctrl + C to drop it without running it.
- Type
whoaand press Tab. It should finish the wordwhoamifor you. If several commands start the same way, press Tab twice to list them.
Key takeaways
- The terminal is the window, the shell is the program in it, and Bash is the usual shell on Linux.
- On Windows,
wsl --installgives you real Linux. On a Mac, Terminal is already there. - Commands are built from a command, options and arguments.
- Capitals matter, and no message usually means it worked.
- Tab finishes words, the up arrow repeats commands, and Ctrl + C stops what’s running.
Check yourself
Three questions. Pick one answer each and you’ll see why.
1. You typed LS and got “command not found”. Why?
ls, LS and Ls are three different things, and only the first one exists.2. Your prompt ends in ~$. What does the ~ tell you?
~ is short for your home folder. The prompt updates as you move around, which you’ll do in the next lesson.3. A command is running and won’t stop. What should you press?
Done? Next you’ll learn how Linux organises its files, and make a folder of your own to practise in.
This lesson is part of the free course Linux and the Command Line, licensed under CC BY-NC-SA 4.0: you may share and adapt it for non-commercial use, with credit to ExamineIP and a link to the original.