By the end of this lesson you will be able to
- Use pwd to say which folder the terminal is working in.
- List a folder with ls, ls -l, ls -a and ls -lh, and read each column of the long listing.
- Move with cd using a folder name, .., ~ and -.
- Create the practice folder ~/practice and move in and out of it confidently.
On a phone or in a file manager you move around by tapping folders. In the terminal you do the same by typing, and you always need to know where you are before you do anything else. Three small commands answer the three questions that matter: where am I, what is here, and how do I go somewhere else. They only look and move, so they cannot damage anything. In this lesson you also make a practice folder, which becomes the safe playground for the rest of the module.
Where am I? pwd
The terminal is always 'standing' in one folder, called the Working directory. Think of walking through a building with your eyes closed: every instruction like 'open the door on your left' only makes sense if you know which room you are in. Commands that use short names, such as ls Documents, look for those names inside the working directory.
When you open Terminal on Ubuntu you start in your Home directory, the folder that belongs to you. The command pwd (print working directory) prints the full File path of the working directory. The prompt also shows a short form: a ~ (tilde) means 'my home directory'.
pwd/home/aminaAmina is a fictional user. On your laptop you will see /home/ followed by your own user name.
What is here? ls
The command ls (list) prints the names of the files and folders in the working directory. With no argument it lists the working directory. With an argument it lists that folder instead, for example ls Documents. Because it only reads, it is one of the safest commands there is.
ls- Marker 1: pwd: the full path of where you are
- Marker 2: ls: the names inside this folder
Read this figure as text
A simulated terminal showing pwd printing /home/amina and ls printing the usual Ubuntu home folders.
A simulated bash terminal with the prompt showing the home directory. Marker 1: the command pwd prints /home/amina. Marker 2: the command ls prints the names Desktop, Documents, Downloads, Music, Pictures, Public, snap, Templates and Videos on one or two lines. On your laptop the list may differ a little. Nothing was changed.
Options that change the view
An option changes how a command behaves. For ls there are three you will use constantly. They can be combined after a single dash, so ls -lah means -l, -a and -h together.
| Command | What it adds |
|---|---|
ls -l | Long listing: one line per item with permissions, owner, size and date. |
ls -a | All: also shows hidden files, whose names start with a dot, plus . (this folder) and .. (the folder above). |
ls -h | Human-readable sizes such as 4.0K or 2.1M. It only matters together with -l. |
ls -lah | All three at once: long, all, human-readable. |
The long listing packs a lot into each line. Reading from left to right: the first character says what the item is (- for a file, d for a directory), the next nine characters are its permissions (the next lessons explain them), then a link count, the owner, the group, the size, the date and finally the name.
drwxr-xr-xType and permissionsd = directory 2 LinksIgnore for nowaminaOwnerWho owns it amina GroupOwning group4096SizeIn bytes Oct 20 10:15 ChangedDate and timenotesNameFile or folderRead this figure as text
A long listing line drwxr-xr-x 2 amina amina 4096 Oct 20 10:15 notes broken into labelled columns.
The line drwxr-xr-x 2 amina amina 4096 Oct 20 10:15 notes has these parts in order. drwxr-xr-x: the first letter d means directory, and the nine letters after it are the permissions. 2: the link count, which you can ignore for now. amina: the owner. amina: the group. 4096: the size in bytes. Oct 20 10:15: the date and time it was last changed. notes: the name.
Going somewhere else: cd
The command cd (change directory) moves the terminal into another folder. It prints nothing when it works. Silence means success, and you can check by looking at the prompt or running pwd. Four forms cover nearly everything you will do.
| Command | Where it takes you |
|---|---|
cd Documents | Into the folder called Documents inside the working directory (a relative path). |
cd .. | Up one level, to the parent folder. Two dots always mean 'the folder above'. |
cd ~ or just cd | Straight home, from wherever you are. |
cd - | Back to the folder you were in just before. It prints that folder's path. |
cd /home/amina/Documents | To an exact address (an absolute path), which works from anywhere. |
- /home/amina (~)Your home directory
- Desktop
- Documents
- Downloads
- Pictures
- practiceNew: your safe playground
Read this figure as text
A folder tree with /home/amina at the top and folders Documents, Downloads, Pictures and practice beneath it.
A tree. The top is /home/amina, your home directory, also written ~. Beneath it are the folders Desktop, Documents, Downloads, Pictures and practice. The practice folder is new and empty, and it is where every exercise in this module happens. From ~/practice, the command cd .. moves up to /home/amina, and cd ~ or cd alone also goes to /home/amina.
Make your practice folder
From now on, every command that creates or changes things is aimed at one folder called practice inside your home directory, written ~/practice. If you ever make a mistake, the worst result is a messy practice folder, never your photos or documents. You make it with mkdir (make directory), which the next lesson explains fully. For now: mkdir creates a new folder with the name you give it.
Create and visit ~/practice
Step 1: Go home first
Type
cdand press Enter, thenpwd.You should see: You see /home/ followed by your user name.
Step 2: Make the folder
Type
mkdir practiceand press Enter.You should see: Nothing is printed. The prompt returns.
Step 3: Check it exists
Type
ls.You should see: The word practice now appears in the list.
Step 4: Step inside
Type
cd practice, thenpwd.You should see: The prompt ends with ~/practice$ and pwd prints /home/amina/practice (with your own name).
Step 5: Look inside, including hidden items
Type
ls -la.You should see: Only two entries,
.and.., because the folder is empty.
- Marker 1: Creates the folder; prints nothing
- Marker 2: Moves in; the prompt changes to ~/practice
- Marker 3: Confirms the full path
- Marker 4: Empty: just . (here) and .. (above)
Read this figure as text
A simulated terminal showing mkdir practice, cd practice, pwd and ls -la of the empty folder.
A simulated bash terminal starting in the home directory. Marker 1: mkdir practice prints nothing. Marker 2: cd practice moves in, and the prompt now shows ~/practice. Marker 3: pwd prints /home/amina/practice. Marker 4: ls -la prints total 8, then a line for . (the practice folder itself) and a line for .. (the home directory above), both starting with d for directory, with permissions drwxr-xr-x and drwxr-x--- respectively. The folder holds nothing else.
Common errors and what they mean
- Marker 1: Capital P: the real folder is practice
- Marker 2: Two dots: go up one level
- Marker 3: A folder that exists: cd works silently
Read this figure as text
A simulated terminal showing cd to a missing folder, cd to a file, and a corrected cd.
A simulated bash terminal in ~/practice. Marker 1: cd Practice fails with bash: cd: Practice: No such file or directory, because the folder name is practice with a small p and Linux cares about capitals. Marker 2: cd .. succeeds and prints nothing, moving up to the home directory. Marker 3: cd Desktop works. A further case, cd on a file name, gives bash: cd: notes.txt: Not a directory.
No such file or directory means that name does not exist where you are looking. Check the capital letters, check the spelling, and check with pwd and ls that you are in the folder you think you are. Not a directory means you gave cd a file, and you can only enter folders. Tab completion (from the previous module) helps here: type cd pra and press Tab.
Practise in the simulated terminal
Use pwd, ls and cd in a safe simulated terminal with its own practice folder. Try cd .. and cd - and watch what each one prints.
Loading lab…
Common mistakes
✖ Instead of: Typing commands without knowing which folder you are in.
✔ Do this: Run
pwdfirst. Everything you type with a short name depends on the working directory.✖ Instead of: Thinking
cdfailed because it printed nothing.✔ Do this: Success is silent. Look at the prompt or run
pwdto confirm.✖ Instead of: Typing
cdfollowed by a file name, or getting the capital letters wrong.✔ Do this:
cdonly enters folders, and names are case sensitive. Uselsto see exact names and Tab to complete them.
If something goes wrong
- bash: cd: practice: No such file or directory
- You are probably not in your home directory. Type
cdto go home, runlsto check that practice is listed, and trycd practiceagain. If it is not listed, runmkdir practice. - mkdir: cannot create directory 'practice': File exists
- The folder is already there, which is fine. Just
cd practice. - ls shows a different list from the lesson.
- Every computer is different. Ubuntu versions and your own files change what appears. Compare how the output is shaped, not the exact names.
Key terms
- Working directory
- The folder the terminal is currently 'in', which commands use unless you give another path.
- Home directory
- Your own personal folder on Linux, where your documents and settings live; written ~ in commands.
- Hidden file
- A file or folder whose name begins with a dot, which ls does not show unless you ask with -a.
- File path
- The written route to a file through the folders that contain it.
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.
Take a tour and set up your practice folder
On your Ubuntu laptop, open Terminal. Run pwd and ls. Create the practice folder with mkdir practice if you have not already, then cd practice and ls -la. Move up with cd .., then run cd Documents followed by pwd, and use cd - to return to the previous folder. Finish with cd on its own.
Challenge: what is hiding in your home folder?
Without being told the commands, compare ls and ls -a in your home directory. Write down three names that appear only with -a. Then use ls -lh on any folder and note one size shown in K or M.
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
- pwd prints where you are; ls prints what is there; cd moves you.
- ls -l, -a and -h change the view: long detail, hidden files, readable sizes.
- cd .. goes up, cd ~ or cd goes home, cd - goes back to the previous folder.
- Silence usually means success; errors say No such file or directory or Not a directory.
- Do every exercise inside ~/practice so mistakes cannot reach your real files.
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)
- GNU Coreutils: ls invocation (GNU Project)