Terminal start Lesson 2 of 12
Where am I? pwd, ls and cd
9 minutes
Learning goals
- Show the folder you are in with pwd.
- List a folder with ls, including hidden files with ls -a.
- Read size, date and name in the output of ls -l.
- Move into a folder with cd and back again.
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/lernerRead 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:
Example:
ls
Documents Downloads Pictures notes.txt projectsSome 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/lernercd .. 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.
Task complete
Solution
cd Downloads
pwd Why: cd is silent when it works. pwd is the quick check that you landed where you wanted.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
ls -a Why: Settings often live in hidden files like .bashrc. When something behaves oddly, ls -a shows you what else is there.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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
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
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works when exactly 2 are chosen. Chosen: 0.
Cards
-
Card 1 of 4
Tap the card or press Space to turn it over.
-
Card 2 of 4
Tap the card or press Space to turn it over.
-
Card 3 of 4
Tap the card or press Space to turn it over.
-
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
What you can do now: pwd, ls, cd Documents
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: done
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: open
- Lesson 10: open
- Lesson 11: open
- Lesson 12: open
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
-
pwdshow where you are -
ls -alist a folder, hidden files included -
ls -lone line per entry with size and date -
cd <folder>go into a folder, cd .. goes back up