terminal.cab

Terminal start Lesson 3 of 12

guestLevel 1Badges and progress0/100 XP, XP to the next levelStreak0

Paths: absolute, relative, ~ and ..

9 minutes

Learning goals

The tree

All files on Linux hang in one big tree. At the very top is the root, written as a single /. Under it are folders like home, etc or tmp. Under home lives lerner, your home folder, and in there your own folders:

ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

The / between names separates the levels: /home/lerner/projects/website means root, then home, then lerner, then projects, then website.

Absolute and relative

A path that starts with / is absolute. It always starts at the root and works no matter where you are:

cd /home/lerner/projects

Purpose: Jumps to a folder by its full path, from wherever you are.

Syntax: cd /PATH/FROM/THE/ROOT

Example:

cd /home/lerner/projects
pwd
/home/lerner/projects

in the glossary: cd

A path without / at the start is relative: the shell starts looking in your working folder. In your home folder, cd projects leads to the same place. Shorter, but only from here.

~ is a shortcut for your home folder. ~/projects is the same as /home/lerner/projects, from anywhere. And cd ~, just like a plain cd, takes you home.

Up and back

.. is the folder above. You can chain it: ../.. is two levels up.

cd ..

Purpose: Goes one folder up.

Syntax: cd ..

Example:

cd projects/website
cd ..
pwd
/home/lerner/projects

in the glossary: cd

cd - takes you back to the folder you were in before, like the back button of a browser. It prints where it took you:

cd -

Purpose: Goes back to the folder you were in before and prints its path.

Syntax: cd -

Example:

cd /tmp
cd -
/home/lerner
cd -
/tmp

in the glossary: cd

Names with spaces

The shell splits your line at spaces. cat Documents/Holiday 2027.txt would look for two files, Documents/Holiday and 2027.txt. To keep the name together, put it in quotes:

cat "Documents/Holiday 2027.txt"

Purpose: Keeps a name with a space together as one name.

Syntax: "NAME WITH SPACE" or NAME\ WITH\ SPACE

Example:

cat "Documents/Holiday 2027.txt"
Where: the coast
When: July
Budget: 1200

in the glossary: cat

Or put a backslash right before the space. It tells the shell: this space is part of the name.

cat Documents/Holiday\ 2027.txt
Where: the coast
When: July
Budget: 1200

ls shows such names in single quotes, like 'Holiday 2027.txt', so you can see where the name starts and ends.

Practice

Terminal task 1/2

Jump into the folder website inside projects, then show with pwd where you are.

Task 1/2: Jump into the folder website inside projects, then show with pwd where you are.

Jump into the folder website inside projects, then show with pwd where you are.

Loading terminal …

lerner@terminal: ~bash
lerner@terminal:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 2/2

Show the content of the file Holiday 2027.txt in the folder Documents.

Task 2/2: Show the content of the file Holiday 2027.txt in the folder Documents.

Show the content of the file Holiday 2027.txt in the folder Documents.

Loading terminal …

lerner@terminal: ~bash
lerner@terminal:~$

Esc, then Tab leaves the terminal

Not done yet

Predict the output

Command

cd projects/website; cd ..; pwd

Before the command, in your home folder ~

  • ~/.bashrc
  • ~/.profile
  • ~/.config/
  • ~/Documents/
  • ~/Downloads/
  • ~/Pictures/
  • ~/notes.txt
  • ~/projects/
What does cd projects/website; cd ..; pwd print?

Check works once you have chosen an answer.

Fill the gap

You are in /home/lerner/projects/website. To get to /home/lerner with .. you type: cd

You are in /home/lerner/projects/website. To get to /home/lerner with .. you type: cd …

Check works once you have typed an answer.

Put in order

Put the levels of /home/lerner/projects/website in order, from the root down.

Steps

  1. projects
  2. website
  3. / (the root)
  4. home
  5. lerner (your home folder)

Now that you can get anywhere, the next lesson is about making things: new folders and files.

Quiz

  1. Question 1 of 4Which of these paths is absolute?

    Check works once you have chosen an answer.

  2. Question 2 of 4What does cd - do?

    Check works once you have chosen an answer.

  3. Question 3 of 4Which commands show the file "Holiday 2027.txt" in Documents? Choose TWO.

    Check works when exactly 2 are chosen. Chosen: 0.

  4. Question 4 of 4You are in /tmp. Where does cd ~/projects take you?

    Check works once you have chosen an answer.

Cards

  1. Card 1 of 4

    Tap the card or press Space to turn it over.

  2. Card 2 of 4

    Tap the card or press Space to turn it over.

  3. Card 3 of 4

    Tap the card or press Space to turn it over.

  4. Card 4 of 4

    Tap the card or press Space to turn it over.

End of the lesson

Still open: 5 exercises, 4 quiz questions

Next: lesson 4, Creating folders and files (8 min)

What you can do now: cd /home/lerner/projects, cd .., cd -, cat "Documents/Holiday 2027.txt"

+0 XP in this lesson

  1. Lesson 1: open
  2. Lesson 2: open
  3. Lesson 3: done
  4. Lesson 4: open
  5. Lesson 5: open
  6. Lesson 6: open
  7. Lesson 7: open
  8. Lesson 8: open
  9. Lesson 9: open
  10. Lesson 10: open
  11. Lesson 11: open
  12. Lesson 12: open
1 of 12

Next: lesson 4, Creating folders and files (8 min) That's enough for today

Path complete

You finished all 12 lessons of Terminal start.

On to Linux Basics: lesson 1, Finding your way around a strange server (8 min) Back to the path

Cheat sheet