🧠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
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:
- ubuntu is who you are: your user name.
- @ just means "at".
- practice is the name of the machine you are on (its hostname).
- : separates the machine from the location.
- ~ is where you are. The tilde means your home folder.
- $ means "ready for your command", and it tells you that you are a normal user. A # there means you are the all-powerful administrator, called root. Be extra careful when you see #.
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
- whoami prints your user name.
- hostname prints the name of the machine.
- pwd means "print working directory": it tells you where you are. You are in /home/ubuntu, your home folder.
- ls lists what is in the current folder. Here it printed nothing at all, and that is correct: your home folder is empty, so there is nothing to list.
- ls -a adds the hidden files. In Linux a file whose name starts with a dot is hidden. Your home folder has three of them, which your account needs to work. The . and .. entries are special, and you will meet them below.
- date prints the date and time.
- echo prints whatever you give it. It is the "hello world" of the command line.
💡 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:
- cd /usr moves to the folder /usr. The prompt now says /usr instead of ~.
- ls shows what is in there: bin games include lib ...
- cd share goes into the share folder, which is inside /usr.
- cd .. goes up one level. The two dots mean "the folder above this one". Back in /usr.
- cd on its own, with nothing after it, takes you home, from anywhere. Lost? Type cd and you are home.
- cd - goes back to wherever you just were. It prints that place for you, and it is a handy "undo".
- cd ~ also means home, written the long way.
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:
- An absolute path starts with / and works from anywhere: /usr/share.
- A relative path does not start with /, and it starts from where you are now: share, or ../lib.
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:
- First column: the type and the permissions, like drwxr-xr-x. The first letter is d for a directory (a folder) and - for an ordinary file. The rest says who may read, write or run it. Lesson 5 explains it fully; for now just notice that it is there.
- Then the number of links, the owner (root), the group (root), the size in bytes, the date it was last changed, and finally the name.
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:
- /home holds each user's personal files. Yours is /home/ubuntu.
- /etc holds the settings of the system and its programs (the name is a historical accident; read it as "configuration").
- /var holds data that changes while the system runs: logs, caches, mail and databases. /var/log is where logs live.
- /usr holds most of the installed programs and their files. /bin and /sbin are the traditional homes of the essential commands; on a modern Ubuntu they are just shortcuts (symbolic links) to folders inside /usr.
- /tmp is for temporary files. It was empty here.
- /root is the home folder of the administrator (the user called root). You are not allowed in there, as you will see in a moment.
- /dev, /proc and /sys are special: they are not real files on a disk, but a window onto devices and the running system. Leave them alone for now.
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
- No such file or directory. The place you named does not exist. Either you misspelled it, or you are in a different folder than you thought. Look at the /USR example: Linux is case sensitive, so /USR is not /usr. (Check where you are with pwd and what is there with ls.)
- Permission denied. The place exists, but you are not allowed in. /root belongs to the administrator. This is Linux protecting itself, and you will meet it again in lesson 5.
- command not found. The shell does not know that command. A typo (LS instead of ls), a missing space (cd.. instead of cd ..), or a program that is not installed.
- And after all that, cd /usr worked normally. One mistake never breaks the next command.
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
- pwd print where you are. ls list what is here. cd FOLDER move there.
- cd or cd ~ go home. cd .. go up one level. cd - go back to where you were.
- ls -l long listing. ls -a include hidden files. ls -lh human sizes. ls -la long and hidden.
- Absolute paths start with /. Relative paths start from where you are.
- Tab completes names. Up arrow recalls commands. Ctrl+C stops. Ctrl+L clears. Ctrl+D leaves.
- help COMMAND for shell built-ins, COMMAND --help for programs.
← Lesson 1 · ↑ All lessons · Lesson 3: Files and Folders: Making, Copying, Moving and Deleting →