🧭 Lesson 2: The Terminal: Where You Are and How to Move Around

The prompt, pwd, ls and cd: how to find your way around without getting lost

Video: The Terminal: Where You Are and How to Move Around (Linux 101 video)
Prefer to watch? This short video runs the lesson's main commands on a real Ubuntu 24.04 machine, with on-screen captions and no voiceover. Click to play, or watch it on YouTube.

What is the terminal?

The terminal is a window where you type commands instead of clicking icons. The program inside it, the one that reads what you type and runs it, is called the shell. On Ubuntu the shell is called bash. You type a command, press Enter, and the computer answers in text. That is the whole idea. It feels strange for about a day, and then it feels fast.

Open your practice machine from the last lesson (docker start -ai practice, or whichever route you chose) and follow along. Everything on this page was run on a real Ubuntu 24.04, and the output you see is what your screen should show. A tip for reading the examples: the first line of each block shows the prompt and the command you type. You do not type the prompt itself, only what comes after the $.

Read the prompt

ubuntu@practice:~$

This little line is packed with information, and once you can read it you always know where you are:

Your first commands

ubuntu@practice:~$ whoami
ubuntu
ubuntu@practice:~$ hostname
practice
ubuntu@practice:~$ pwd
/home/ubuntu
ubuntu@practice:~$ ls
ubuntu@practice:~$ ls -a
.  ..  .bash_logout  .bashrc  .profile
ubuntu@practice:~$ date
Mon Oct  5 13:36:26 UTC 2026
ubuntu@practice:~$ echo Hello, Linux
Hello, Linux

💡 Commands are case sensitive and spaces matter. ls works, LS does not, and cd.. is not the same as cd ... You will see exactly what the errors look like further down.

The folder tree

Your files live in folders, and folders live inside other folders, all the way up to one folder that holds everything. That top folder is called root, and it is written as a single slash: /. (Do not confuse it with the user called root. Same word, different thing. Linux is full of these, and every beginner trips on this one.) Picture an upside-down tree: / at the top, branches below it.

The command pwd prints the path to where you are, from the top down. /home/ubuntu means: start at /, go into home, then into ubuntu. Every user gets a folder inside /home, and the shell lets you write your own as ~ for short.

Moving around with cd

cd means "change directory". Watch the prompt change as you move, because the location in it follows you:

ubuntu@practice:~$ pwd
/home/ubuntu
ubuntu@practice:~$ cd /usr
ubuntu@practice:/usr$ pwd
/usr
ubuntu@practice:/usr$ ls
bin  games  include  lib  lib64  libexec  local  sbin  share  src
ubuntu@practice:/usr$ cd share
ubuntu@practice:/usr/share$ pwd
/usr/share
ubuntu@practice:/usr/share$ cd ..
ubuntu@practice:/usr$ pwd
/usr
ubuntu@practice:/usr$ cd
ubuntu@practice:~$ pwd
/home/ubuntu
ubuntu@practice:~$ cd /usr/share
ubuntu@practice:/usr/share$ cd -
/home/ubuntu
ubuntu@practice:~$ cd ~
ubuntu@practice:~$ pwd
/home/ubuntu

Step by step:

How do you find your way around a Linux machine?<br>
Same way as anywhere: you look at the sign, pwd, and when lost, you cd home.

Absolute and relative paths

There are two ways to say where something is:

ubuntu@practice:~$ cd /usr/share
ubuntu@practice:/usr/share$ cd ../lib
ubuntu@practice:/usr/lib$ pwd
/usr/lib
ubuntu@practice:/usr/lib$ cd /usr
ubuntu@practice:/usr$ cd local
ubuntu@practice:/usr/local$ pwd
/usr/local
ubuntu@practice:/usr/local$ cd /home/ubuntu
ubuntu@practice:~$ pwd
/home/ubuntu

From /usr/share, the relative path ../lib means "go up one folder to /usr, then into lib", and it landed in /usr/lib. From /usr, cd local found /usr/local right there. And cd /home/ubuntu is the absolute way to get back home, which works from any starting point.

Two special names are worth remembering: .. is the folder above, and . is the folder you are in.

Looking closer with ls

ls has options, written with a dash. Here are the three you will use all the time:

ubuntu@practice:~$ ls -l /usr
total 48
drwxr-xr-x  2 root root 12288 Sep 17 02:29 bin
drwxr-xr-x  2 root root  4096 Apr 22  2024 games
drwxr-xr-x  2 root root  4096 Apr 22  2024 include
drwxr-xr-x 13 root root  4096 Sep 17 02:29 lib
drwxr-xr-x  2 root root  4096 Sep 17 02:29 lib64
drwxr-xr-x  4 root root  4096 Sep 17 02:20 libexec
drwxr-xr-x 10 root root  4096 Sep 17 02:20 local
drwxr-xr-x  2 root root  4096 Sep 17 02:29 sbin
drwxr-xr-x 34 root root  4096 Sep 17 02:29 share
drwxr-xr-x  2 root root  4096 Apr 22  2024 src
ubuntu@practice:~$ ls -la
total 20
drwxr-x--- 2 ubuntu ubuntu 4096 Sep 17 02:29 .
drwxr-xr-x 3 root   root   4096 Sep 17 02:29 ..
-rw-r--r-- 1 ubuntu ubuntu  220 Mar 31  2024 .bash_logout
-rw-r--r-- 1 ubuntu ubuntu 3771 Mar 31  2024 .bashrc
-rw-r--r-- 1 ubuntu ubuntu  807 Mar 31  2024 .profile
ubuntu@practice:~$ ls -lh /etc/hostname
-rw-r--r-- 1 root root 9 Oct  5 13:36 /etc/hostname

ls -l is the long listing. Each row is one item, and the columns mean:

ls -la combines two options: long, and all (including hidden files). ls -lh adds h for human-readable sizes: a big file shows as 4.0K or 12M instead of a long number of bytes. Our example file, /etc/hostname, is only 9 bytes, so it still shows 9. Options can be combined after one dash, in any order.

A map of the Linux filesystem

Every Linux machine has the same top-level layout. This is what the top of the tree looks like on the practice machine:

ubuntu@practice:~$ ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
ubuntu@practice:~$ ls /home
ubuntu
ubuntu@practice:~$ ls /tmp
ubuntu@practice:~$ ls /var
backups  cache  lib  local  lock  log  mail  opt  run  spool  tmp

You do not need to memorise it. Here is what the main folders are for, so the names stop looking like random letters:

When things go wrong

Errors are not scary. They are the computer telling you, in words, what it did not understand. Here are the four you will meet in your first week, all on purpose:

ubuntu@practice:~$ cd documents
bash: cd: documents: No such file or directory
ubuntu@practice:~$ cd /root
bash: cd: /root: Permission denied
ubuntu@practice:~$ ls /nowhere
ls: cannot access '/nowhere': No such file or directory
ubuntu@practice:~$ cd /USR
bash: cd: /USR: No such file or directory
ubuntu@practice:~$ LS
bash: LS: command not found
ubuntu@practice:~$ cd..
bash: cd..: command not found
ubuntu@practice:~$ cd /usr
ubuntu@practice:/usr$ pwd
/usr

Work faster: Tab, history and Ctrl+C

Three habits will save you a thousand keystrokes. First, press Tab to finish a name for you. Type the start of a path and press Tab:

ubuntu@practice:~$ cd /usr/
ubuntu@practice:/usr$ cd share/
ubuntu@practice:/usr/share$ ls /usr/l
lib/     lib64/   libexec/ local/   
ubuntu@practice:/usr/share$ ls /usr/l^C

In that session cd /us and Tab completed to cd /usr/, and cd sh completed to cd share/. When more than one name could fit, pressing Tab twice lists the choices, as it did for /usr/l (lib, lib64, libexec and local). Tab also protects you from typos, because if it completes the name, the name exists.

Second, the shell remembers what you typed. Press the Up arrow to bring back your previous command, and press it again to go further back. The history command lists them all, and !! means "run the last command again":

ubuntu@practice:~$ echo one
one
ubuntu@practice:~$ echo two
two
ubuntu@practice:~$ !!
echo two
two
ubuntu@practice:~$ history
    1  echo one
    2  echo two
    3  history

Third, Ctrl+C stops a command that is taking too long or running away. Here sleep 30 was asked to wait 30 seconds, and was cancelled with Ctrl+C. The ^C shows the keypress:

ubuntu@practice:~$ sleep 30
^C

Two more keys: Ctrl+L clears the screen (so does the clear command), and Ctrl+D on an empty line leaves the shell, like exit.

Getting help

You will not remember every option, and nobody does. The shell has built-in help. For commands built into the shell itself, like pwd and cd, use help:

ubuntu@practice:~$ help pwd
pwd: pwd [-LP]
    Print the name of the current working directory.
    
    Options:
      -L	print the value of $PWD if it names the current working
    		directory
      -P	print the physical directory, without any symbolic links
    
    By default, `pwd' behaves as if `-L' were specified.
    
    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.
ubuntu@practice:~$ man ls
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, including manpages, you can run the 'unminimize'
command. You will still need to ensure the 'man-db' package is installed.

For ordinary programs, add --help to the command (ls --help prints a summary of its options). On a normal Ubuntu, man ls opens the full manual page (press q to leave it), but in this stripped-down practice container the manuals were removed, so you get the message above instead. Manual pages are written as reference, so they can feel dense at first. That is normal. If one is hard to follow, a web search for the command name plus "examples" almost always finds a friendlier explanation, and you can always ask on the wiki or the contact page.

🧪 Try it yourself

1. Print your user name, the machine name, and your current folder, using three separate commands. 2. Move to /var/log with one command, then back to your home folder with one command. (Check your answer: the prompt should show ~ again.) 3. From /etc, get home with the shortest command you can. (Hint: it is two letters.) 4. Use Tab to type cd /usr/share while typing as few characters as possible. 5. Make a mistake on purpose: cd /Usr. Read the error. What would you check first?

The cheat sheet

← Lesson 1 · ↑ All lessons · Lesson 3: Files and Folders: Making, Copying, Moving and Deleting →