The Academy

Loading the search index…

Searches the academy on this device only.

Finding your way: pwd, ls and cd

Learn three commands that only look and move: pwd shows where you are, ls shows what is there and cd takes you somewhere else. You also make a practice folder so every later exercise is safe.

25 minbeginnerUbuntu/LinuxPractical task needs a laptop or desktop

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).

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'.

Terminal (Linux) · you can run this on your own computer
pwd
Text
/home/amina

Amina 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.

Terminal (Linux) · you can run this on your own computer
ls
Simulated interface: not a real screenshot

A simulated terminal in the home directory running pwd and ls.

amina@laptop: ~ (simulated)
  1. Marker 1: pwd: the full path of where you are
  2. Marker 2: ls: the names inside this folder
A simulated terminal in the home directory running pwd and ls.
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.

Common ls options
CommandWhat it adds
ls -lLong listing: one line per item with permissions, owner, size and date.
ls -aAll: also shows hidden files, whose names start with a dot, plus . (this folder) and .. (the folder above).
ls -hHuman-readable sizes such as 4.0K or 2.1M. It only matters together with -l.
ls -lahAll 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.

Diagram

One line of ls -l split into its parts.

drwxr-xr-xType and permissionsd = directory
2 LinksIgnore for now
aminaOwnerWho owns it
amina GroupOwning group
4096SizeIn bytes
Oct 20 10:15 ChangedDate and time
notesNameFile or folder
One line of ls -l split into its parts.
Read 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.

Ways to use cd
CommandWhere it takes you
cd DocumentsInto 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 cdStraight home, from wherever you are.
cd -Back to the folder you were in just before. It prints that folder's path.
cd /home/amina/DocumentsTo an exact address (an absolute path), which works from anywhere.
Diagram

A home directory as a tree, with the practice folder you are about to make.

  • /home/amina (~)Your home directory
    • Desktop
    • Documents
    • Downloads
    • Pictures
    • practiceNew: your safe playground
A home directory as a tree, with the practice folder you are about to make.
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

  1. Step 1: Go home first

    Type cd and press Enter, then pwd.

    You should see: You see /home/ followed by your user name.

  2. Step 2: Make the folder

    Type mkdir practice and press Enter.

    You should see: Nothing is printed. The prompt returns.

  3. Step 3: Check it exists

    Type ls.

    You should see: The word practice now appears in the list.

  4. Step 4: Step inside

    Type cd practice, then pwd.

    You should see: The prompt ends with ~/practice$ and pwd prints /home/amina/practice (with your own name).

  5. Step 5: Look inside, including hidden items

    Type ls -la.

    You should see: Only two entries, . and .., because the folder is empty.

Simulated interface: not a real screenshot

A simulated terminal: make the practice folder, enter it, and look inside.

amina@laptop (simulated)
  1. Marker 1: Creates the folder; prints nothing
  2. Marker 2: Moves in; the prompt changes to ~/practice
  3. Marker 3: Confirms the full path
  4. Marker 4: Empty: just . (here) and .. (above)
A simulated terminal: make the practice folder, enter it, and look inside.
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

Simulated interface: not a real screenshot

Two cd errors and the fix, in a simulated terminal.

amina@laptop (simulated)
  1. Marker 1: Capital P: the real folder is practice
  2. Marker 2: Two dots: go up one level
  3. Marker 3: A folder that exists: cd works silently
Two cd errors and the fix, in a simulated terminal.
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 pwd first. Everything you type with a short name depends on the working directory.

  • ✖ Instead of: Thinking cd failed because it printed nothing.

    ✔ Do this: Success is silent. Look at the prompt or run pwd to confirm.

  • ✖ Instead of: Typing cd followed by a file name, or getting the capital letters wrong.

    ✔ Do this: cd only enters folders, and names are case sensitive. Use ls to 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 cd to go home, run ls to check that practice is listed, and try cd practice again. If it is not listed, run mkdir 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.

Guided exerciseNeeds a laptop or desktop

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.

You have succeeded when:
Independent challengeNeeds a laptop or desktop

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.

You have succeeded when:

Knowledge check

7 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.

  1. Question 1.What does the command pwd do?
  2. Question 2.Which command lists every item, including hidden ones, in a long detailed format?
  3. Question 3.Match each cd command to where it takes you.
  4. Question 4.If cd prints nothing and returns to the prompt, it has failed.
  5. Question 5.You are in your home directory and type cd Practice. The terminal replies: bash: cd: Practice: No such file or directory. You made a folder called practice a minute ago.What is the most likely cause?
  6. Question 6.Put these steps in order to create and enter your practice folder.
    1. Type cd to go home
    2. Type cd practice and press Enter
    3. Type mkdir practice
    4. Type ls and see practice listed
  7. Question 7.In the line drwxr-xr-x 2 amina amina 4096 Oct 20 10:15 notes, what does the first letter d tell you?

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.

On this page