terminal.cab

Terminal start Lesson 2 of 12

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

Where am I? pwd, ls and cd

9 minutes

Learning goals

Where am I: pwd

The shell always works in one folder, the working folder. Right after you open the terminal, that is your home folder. pwd prints its full path:

pwd

Purpose: Prints the full path of the folder you are in.

Syntax: pwd

Example:

pwd
/home/lerner

in the glossary: pwd

Read it like a route: start at the top /, into home, into lerner. More on paths in the next lesson.

What is here: ls

ls lists what lies in the working folder. Folders and files appear side by side, sorted by name:

ls

Purpose: Lists the files and folders in a folder, by default the one you are in.

Syntax: ls [OPTION]... [FOLDER]...

Options:

  • -a also show hidden entries, whose names start with a dot
  • -l one line per entry with size, date and more

Example:

ls
Documents  Downloads  Pictures  notes.txt  projects

in the glossary: ls

Some files are hidden: their names start with a dot. They usually hold settings, and ls leaves them out so they do not clutter the list. With -a (for "all") you see them too:

ls -a
.   .bashrc  .profile   Downloads  notes.txt
..  .config  Documents  Pictures   projects

The two entries . and .. are in every folder. . is the folder itself, .. the one above it. You will use .. a lot soon.

More detail: ls -l

ls -l gives one line per entry. For now, look only at the last three columns: size in bytes, date of the last change, and name. A d at the very start of the line marks a folder. The letters after it are permissions, a topic for later.

ls -l Downloads
total 196
-rw-r--r-- 1 lerner lerner  48000 Oct 11 16:00 invoice.pdf
-rw-r--r-- 1 lerner lerner 150000 Oct 15 20:00 photo.jpg

Here photo.jpg has 150000 bytes, about 150 KB, and was last changed on October 15 at 20:00. You can put a folder name after ls or ls -l to look into it without walking there.

Walking around: cd

cd (change directory) makes another folder your working folder. It prints nothing when it works, so check with pwd:

cd Documents

Purpose: Changes the folder you are working in.

Syntax: cd [FOLDER]

Example:

cd Documents
pwd
/home/lerner/Documents
cd ..
pwd
/home/lerner

in the glossary: cd

cd .. takes you one folder up, back where you came from. And cd on its own always brings you home, wherever you are. Notice how the prompt changes along the way: lerner@terminal:~/Documents$ while you are in Documents.

Practice

Find your way around the home folder. Each task starts fresh in /home/lerner.

Terminal task 1/2

Go into the folder Downloads, then show with pwd where you are now.

Task 1/2: Go into the folder Downloads, then show with pwd where you are now.

Go into the folder Downloads, then show with pwd where you are now.

Loading terminal …

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

Esc, then Tab leaves the terminal

Not done yet

Terminal task 2/2

List your home folder so that the hidden files appear as well.

Task 2/2: List your home folder so that the hidden files appear as well.

List your home folder so that the hidden files appear as well.

Loading terminal …

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

Esc, then Tab leaves the terminal

Not done yet

Fill the gap

Run ls -l Downloads in the terminal above. The file invoice.pdf is bytes large.

Run ls -l Downloads in the terminal above. The file invoice.pdf is … bytes large.

Check works once you have typed an answer.

Find the error

This command answers "No such file or directory". Tap the part that is wrong.

Parts of the command

Check works once you have tapped a part.

Build the command

Build the command that shows the folder Downloads with one line per file, including the size.

Your command

    Tap the blocks below to build the command.

    Building blocks

    Check works once your command has at least one block.

    Next time: paths. How to jump anywhere in one step, and what /, ~ and .. really mean.

    Quiz

    1. Question 1 of 4What does pwd print?

      Check works once you have chosen an answer.

    2. Question 2 of 4Why does ls not show the file .bashrc?

      Check works once you have chosen an answer.

    3. Question 3 of 4You are in /home/lerner/Documents. Where does cd .. take you?

      Check works once you have chosen an answer.

    4. Question 4 of 4What can you read from the line -rw-r--r-- 1 lerner lerner 150000 Oct 15 20:00 photo.jpg? Choose TWO.

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

    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 3, Paths: absolute, relative, ~ and .. (9 min)

    What you can do now: pwd, ls, cd Documents

    +0 XP in this lesson

    1. Lesson 1: open
    2. Lesson 2: done
    3. Lesson 3: open
    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 3, Paths: absolute, relative, ~ and .. (9 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