Lesson 1 of 720 minutesHands-on

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.

  1. Press Windows, type PowerShell, right-click it and choose Run as administrator.
  2. Run this command, then restart your computer when it finishes:
wsl --install
  1. Press Windows, type Ubuntu and open it. The first launch takes a moment while it unpacks.
  2. 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:~$
PartWhat it means
samThe user you’re logged in as
laptopThe 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

  1. Type each of these and press Enter. Who are you?
    whoami
  2. Where are you?
    pwd
  3. What’s the date, according to this computer?
    date
  4. Make it say something back:
    echo Hello from the terminal
  5. 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
  6. Now get it wrong on purpose, with capitals:
    LS
    You’ll get command not found, perhaps with a suggestion. Linux treats capitals and small letters as different, so ls and LS are 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 terminal

The 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
PartExampleWhat it does
CommandlsThe program to run: list files
Option-lChanges how it behaves: show a long, detailed list
Argument/etcWhat 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

KeyWhat it does
TabFinishes 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 + CStops whatever is running and gives you a fresh prompt. It doesn’t copy here
Ctrl + LClears the screen. clear does the same

Try it yourself ยท part 3

Stop a command that won’t stop

  1. On Linux and Mac, ping keeps going until you stop it. Start it:
    ping examineip.com
  2. 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.
  3. Press โ†‘ to see the command again, then Ctrl + C to drop it without running it.
  4. Type whoa and press Tab. It should finish the word whoami for you. If several commands start the same way, press Tab twice to list them.
Pasting into the terminal. Because Ctrl + C means “stop” here, copy and paste use different keys. In the Ubuntu window and on most Linux terminals, paste with Ctrl + Shift + V or a right-click. On a Mac, Cmd + V works as usual.

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 --install gives 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?

2. Your prompt ends in ~$. What does the ~ tell you?

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.

Scroll to Top