By the end of this lesson you will be able to
- Say which directory the terminal is working in and why it matters.
- Tell an absolute path from a relative path and write both for the same file.
- Explain why `Notes` and `notes` are different on Linux and how to handle spaces with quotes.
- Use the Up arrow, Tab and Ctrl+C to repeat, complete and cancel commands.
Most beginner errors in the terminal come from four small things: being in a different folder than you thought, a wrong capital letter, a space in a name, or a typing slip in a long name. This lesson gives you a clear picture of each and three keyboard habits that remove most typing mistakes. It builds on the file-path ideas you met in the folders lesson.
The terminal is always somewhere
A graphical file manager shows you one folder at a time. The terminal works the same way, but it does not draw the folder. Instead, the shell remembers a current directory, also called the Working directory. When you give a command a name such as report.txt, the shell looks for it in the working directory unless you say otherwise. The prompt shows the working directory: ~ means your home folder, and ~/practice means a folder called practice inside it.
Imagine standing in a room of a house. If you say 'pass me the lamp', people assume you mean the lamp in this room. To mean a lamp in another room you must say which room. A command works the same way.
Absolute and relative paths
An Absolute path gives the complete route from the very top of the file system, which is written / and called the root. It always starts with a slash and works from anywhere, like a full postal address. A Relative path starts from where you are now, like saying 'next door, second house'. It does not start with a slash and only works from the right starting place.
- /Root: the top of everything
- home
- aminaHome folder, also written ~
- Documents
- practiceSafe practice folder
- notes.txtThe file we want
Read this figure as text
A folder tree from the root through home and amina to practice and notes.txt, used to show absolute and relative paths.
A folder tree. The root folder is /. Inside it is home. Inside home is amina, which is Amina's home folder and also written ~. Inside amina are Documents and practice. Inside practice is the file notes.txt. If the working directory is /home/amina, the relative path to the file is practice/notes.txt. The absolute path, which works from anywhere, is /home/amina/practice/notes.txt.
/RootTop of everythinghomeFolderAll users live here/SlashSeparatoraminaFolderYour home folder/SlashSeparatorpracticeFolderInside home/SlashSeparatornotes.txtFileThe targetRead this figure as text
The path /home/amina/practice/notes.txt split into the root slash, folder names and the file name.
The absolute path /home/amina/practice/notes.txt has these parts. The first slash is the root, the top of the file system. home is the folder holding all users' home folders. amina is Amina's home folder. practice is the folder inside it. The slashes between names separate folders. notes.txt is the file at the end. Reading left to right moves deeper into the tree.
| Symbol | Meaning | Example |
|---|---|---|
/ | The root, the top of the file system | /home/amina |
~ | Your home directory | ~/practice is /home/amina/practice |
. | The current directory | ./notes.txt |
.. | The parent: one folder up | ../Documents |
Paths are used by every command that touches files. Compare the two commands below. Both do the same thing when you stand in /home/amina, but only the second works from every other folder. ls lists the contents of a folder.
ls practice
ls /home/amina/practiceCapital letters count
Linux is case sensitive: it treats Documents, documents and DOCUMENTS as three different names. The commands themselves are lower case. This surprises people used to Windows, which usually ignores capitals. If the folder is really called Documents and you type documents, the shell does not guess.
- Marker 1: Exact capital letter: works
- Marker 2: Different capital letter: a different name, so an error
Read this figure as text
A simulated terminal where ls Documents works but ls documents prints a no such file or directory error.
A simulated bash terminal in the home folder. The learner types ls Documents and gets a list: Letters and report.odt (marker 1). Then the learner types ls documents with a small d, and the answer is ls: cannot access 'documents': No such file or directory (marker 2). The folder exists, but the name with a small d does not, because Linux treats capitals as part of the name.
Spaces and quotes
The shell uses spaces to separate parts of a command. So if a folder is called My Notes, the command ls My Notes is read as two arguments: a folder My and a folder Notes. Neither exists, so you get two errors. To keep the name in one piece, wrap it in quotes. Quoting tells the shell: treat everything between the marks as a single item.
echo Hello world
echo "Hello world"The first command prints Hello world with a single space, because the shell throws the extra spaces away when splitting the command into parts. The second keeps all the spaces because the quotes made one part. You can use straight double quotes "like this" or single quotes 'like this'. Use the plain quote keys on the keyboard, not curly quotes copied from a web page.
Three habits that save typing and mistakes
History. The shell remembers what you typed. Press the Up arrow to bring back the previous command, again for the one before, and Down arrow to go forward. Press Enter to run it, or edit it first with the left and right arrows. The command history prints the numbered list of earlier commands. Pressing Ctrl+R then typing a few letters searches backwards through that Command history.
Tab completion. Type the first few letters of a file or folder name and press Tab. If only one name starts with those letters, the shell completes it for you. If several do, press Tab twice to see the choices, type one more letter and press Tab again. This is Tab completion. It saves typing, and it also proves the name exists: if Tab adds nothing, you probably misspelt it or are in the wrong folder.
- Step 1: Type the startcd Doc
- Step 2: Press TabOne match fills in
- Step 3: Several matches?Tab twice, add a letter
- Step 4: Press EnterRun the command
Read this figure as text
A flow of four steps showing typing a few letters, pressing Tab, choosing between several matches and pressing Enter.
Four steps. 1: Type the start of a name, for example cd Doc. 2: Press Tab. If only one name matches, the shell fills in the rest, giving cd Documents/. 3: If several names match, press Tab twice to see the list, then type one more letter so that only one matches and press Tab again. 4: Press Enter to run the command. If Tab does nothing, no name matches: check the spelling, the capital letters and the folder you are in.
Ctrl+C. If a command is taking too long, producing endless output, or you started something by mistake, hold Ctrl and press C. This sends a request to stop the running command and returns you to the prompt. It does not copy text: inside a terminal, copy and paste use Ctrl+Shift+C and Ctrl+Shift+V. The command sleep 30 simply waits for 30 seconds, which makes it a harmless way to practise.
- Marker 1: The command waits; no prompt is shown while it runs
- Marker 2: Ctrl+C was pressed: the command is told to stop
- Marker 3: The prompt is back; you can type again
Read this figure as text
A simulated terminal where sleep 30 is started and then stopped with Ctrl+C, after which the prompt returns.
A simulated bash terminal. The learner types sleep 30 (marker 1), which waits 30 seconds and shows no prompt while it runs. The learner then presses Ctrl+C, and the terminal shows the characters ^C (marker 2). The command stops and a new prompt appears, so the shell is ready again (marker 3).
Common mistakes
✖ Instead of: Typing a file name without checking which folder you are in.
✔ Do this: Run
pwdandlsfirst. Relative names only work from the right place.✖ Instead of: Retyping long names by hand and making typing slips.
✔ Do this: Type the first letters and press Tab. If Tab does nothing, stop and look for a spelling or capital-letter mistake.
✖ Instead of: Using Ctrl+C to copy text in the terminal.
✔ Do this: Use Ctrl+Shift+C to copy and Ctrl+Shift+V to paste. Ctrl+C stops the running command.
If something goes wrong
- ls: cannot access 'x': No such file or directory.
- Check three things in order: the spelling, the capital letters, and the folder you are in (run
pwd). Use Tab to let the shell complete the name. - Tab completion does nothing.
- No name starts with what you typed, or you are in a different folder. Press Tab twice to see matches. If there are none, check
pwdandls. - The terminal seems frozen and the prompt does not return.
- A command is probably still running. Press Ctrl+C. If you typed an opening quote mark and forgot the closing one, the shell waits for more: press Ctrl+C to cancel and start the line again.
Key terms
- Working directory
- The folder the terminal is currently 'in', which commands use unless you give another path.
- Absolute path
- The complete address of a file or folder, starting from the very top of the file system.
- Relative path
- A file location described starting from the folder you are in now.
- Case sensitivity
- When a system treats capital and small letters as different.
- Quoting
- Putting quotation marks around text in a command so the shell treats it as one piece.
- Tab completion
- Pressing the Tab key in the terminal to finish a file or command name for you.
- Command history
- The list of commands you have typed earlier, which you can recall instead of retyping.
Practise it for real
Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.
Paths, history and Tab on your laptop
Open Terminal. Run pwd. Then run ls /home and ls ~, and compare the two outputs. Type ls Doc and press Tab to let the shell complete it, then press Enter. Press the Up arrow twice and watch earlier commands return. Run sleep 30 and stop it with Ctrl+C. All of these only display information.
Challenge: write the paths
Using the tree in this lesson, write down the absolute path of notes.txt. Then write the relative path to it if you are standing in /home/amina/Documents, using ... Finally, write a command that lists a folder named Holiday Photos correctly, and explain why it needs quotes.
Knowledge check
7 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.
Summary
- The terminal always has a working directory, shown in the prompt and by `pwd`.
- Absolute paths start at `/` and work anywhere; relative paths start where you are.
- `~` is home, `.` is here and `..` is one folder up.
- Linux is case sensitive, and spaces split a command into parts, so use quotes round names with spaces.
- Up arrow, Tab and Ctrl+C make typing safer, quicker and cancellable.
Checklist: can you do these?
Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).
Related lessons
References and further reading
Official sources for details that can change between versions.
- The Linux command line for beginners (Ubuntu)
- Bash Reference Manual: quoting (GNU Project)