Terminal start Lesson 9 of 12
Faster
10 minutes
Learning goals
- Let Tab complete names and paths instead of typing them out.
- Bring back earlier commands with the arrow keys and search them with Ctrl-R.
- Cancel a line with Ctrl-C and clear the screen with Ctrl-L, also on the phone with the extra key bar.
Tab completes
Type the start of a name and press Tab. If only one file or folder fits, the terminal writes the rest. If several fit, nothing happens at first; press Tab a second time and you see the choices. In this course they also appear as chips you can tap.
Tab even takes care of awkward names. cat Doc, Tab, Hol, Tab gives you this line, with a backslash before the space:
cat Documents/Holiday\ 2027.txt
Purpose: What Tab writes for you after cat Doc, Tab, Hol, Tab.
Syntax: Tab
Example:
cat Documents/Holiday\ 2027.txt
Where: the coast
When: July
Budget: 1200The history: arrow keys and Ctrl-R
The up arrow brings back your last command, press it again for the one before. The down arrow goes forward again. You
can change the line before you press Enter. history shows the whole list:
history
Purpose: Lists your earlier commands with a number.
Syntax: history
Example:
ls Downloads
invoice.pdf photo.jpg
history
1 ls Downloads
2 historyIs the command further back? Press Ctrl-R and type a piece of it, for example 404. The terminal shows the newest
command that contains it. Enter runs it right away, Esc puts it on the line so you can change it first.
Ctrl-C and Ctrl-L
- Ctrl-C cancels. Half-typed line, wrong idea, or a command that does not stop: Ctrl-C and you are back at a fresh prompt. Nothing of the line runs.
- Ctrl-L clears the screen, just like the command
clear. Your history stays.
clear
Purpose: Clears the screen. Ctrl-L does the same.
Syntax: clear
Example:
clearOn the phone
The bar above the keyboard has the keys a phone lacks. Tab and the arrows are right there. For Ctrl, tap Ctrl in the bar
and then the letter on the keyboard: Ctrl, then c is Ctrl-C. Below the terminal, the chips under "Recent commands" are
your history to tap.
Practice
Terminal task 1/3
Show the holiday plan in Documents with cat. Let Tab write the name: cat Doc, Tab, Hol, Tab, Enter.
Task 1/3: Show the holiday plan in Documents with cat. Let Tab write the name: cat Doc, Tab, Hol, Tab, Enter.
Show the holiday plan in Documents with cat. Let Tab write the name: cat Doc, Tab, Hol, Tab, Enter.
Task complete
Solution
cat Documents/Holiday\ 2027.txt Why: Names with spaces are easy to get wrong by hand. Tab adds the backslash for you, so the name stays in one piece.
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/3
Run grep 404 projects/website/server.log. Then bring the line back with the up arrow, add > errors.txt at the end and press Enter. The hits should end up in errors.txt in your home folder.
Task 2/3: Run grep 404 projects/website/server.log. Then bring the line back with the up arrow, add > errors.txt at the end and press Enter. The hits should end up in errors.txt in your home folder.
Run grep 404 projects/website/server.log. Then bring the line back with the up arrow, add > errors.txt at the end and press Enter. The hits should end up in errors.txt in your home folder.
Task complete
Solution
grep 404 projects/website/server.log
grep 404 projects/website/server.log > errors.txt Why: First look at the result on the screen, then save it to a file. The up arrow makes the second step one short addition.
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 3/3
Show the first 3 lines of projects/website/server.log with head -n 3. Clear the screen with Ctrl-L. Then press Ctrl-R, type head and press Enter to run the line again.
Task 3/3: Show the first 3 lines of projects/website/server.log with head -n 3. Clear the screen with Ctrl-L. Then press Ctrl-R, type head and press Enter to run the line again.
Show the first 3 lines of projects/website/server.log with head -n 3. Clear the screen with Ctrl-L. Then press Ctrl-R, type head and press Enter to run the line again.
Task complete
Solution
head -n 3 projects/website/server.log
clear
head -n 3 projects/website/server.log Why: Ctrl-R finds a line even if you ran fifty others since. You only need to remember a piece of it.
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
To throw away the line you are typing and get a fresh prompt, press Ctrl-.
To throw away the line you are typing and get a fresh prompt, press Ctrl-….
Check works once you have typed an answer.
Put in order
You want to change a long command from earlier before running it again. Put the steps in order.
Steps
- Type a piece of the old command.
- Press Esc to put the hit on the line.
- Change the line and press Enter.
- Press Ctrl-R.
From now on, try to type no path in full. Next up: finding things in files and folders.
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: cat Documents/Holiday\ 2027.txt, history, clear
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: done
- 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
-
Tabcomplete names and paths -
↑ ↓earlier and later commands -
Ctrl-Rsearch the history -
Ctrl-Ccancel the line -
Ctrl-L, clearclear the screen