Linux Basics Lesson 3 of 38
Help and history
7 minutes
Learning goals
- Look up a command with man and --help, and tell with type what a name really is.
- Find a command again with history and Ctrl-R instead of typing it once more.
- Know why man -k helps when you have forgotten the name of a command.
You know man from Terminal-Start, lesson 8, and the history from
lesson 9. This is how they save you on a server.
The manual: man
man ls opens the page in the same viewer as less, so you already know the keys: /WORD searches, n goes to the next
match, q ends it. The block shows the top of the page; in the terminal man ls gives you the full-screen view.
man ls
Purpose: Opens the manual page of a command. It works like less, q ends it.
Syntax: man COMMAND
Options:
Example:
man ls | head -n 5
NAME
ls - lists what is in a directory
SYNOPSIS
ls [OPTION]... [FILE]...For the short version, ask the command itself with --help:
head --help | head -n 1
Usage: head [OPTION]... [FILE]...
You forgot the name
man wants a name. If that is exactly what you have forgotten, man -k rename (the same as apropos rename) searches
the short descriptions of all manual pages on a real server and lists what fits, such as mv. This simulator has no such
index and only explains the option. Good to know: help is something else, it only knows what is built into bash, such as
cd. That is why help rename finds nothing useful.
What is this name, anyway?
type tells you what the shell would run. A built-in has no manual page of its own, and an alias may hide a different
command behind a familiar name:
type cd
cd is a shell builtin
type ls
ls is /usr/bin/ls
What did I type?
history lists your commands with numbers. !! runs the last one again, and !42 number 42. The fastest way is Ctrl-R:
press it, type a few letters, and the shell searches backwards while you type. Enter runs the match.
history
Purpose: Lists the commands you typed, with numbers.
Syntax: history [COUNT]
Options:
Example:
hostname
web-01
whoami
lerner
history
1 hostname
2 whoami
3 historyPractice
Terminal task 1/2
Print the name of this machine with hostname, then show your history so that the line appears in it.
Task 1/2: Print the name of this machine with hostname, then show your history so that the line appears in it.
Print the name of this machine with hostname, then show your history so that the line appears in it.
Task complete
Solution
hostname
history Why: From now on you can reach that line with the up arrow, with Ctrl-R or with its number. You only ever type it once.
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
Find out with type whether cd is a program in /usr/bin or built into the shell.
Task 2/2: Find out with type whether cd is a program in /usr/bin or built into the shell.
Find out with type whether cd is a program in /usr/bin or built into the shell.
Task complete
Solution
type cd Why: cd has to be built in. A separate program could only change its own folder, not the one of your shell. So cd has no manual page of its own; help cd explains 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.
Predict the output
Command
type lsBefore the command, in your home folder ~
- ~/.bashrc
- ~/.profile
- ~/.secret
- ~/Documents/
- ~/logs/
- ~/notes.txt
- ~/projects/
- ~/archive/
Check works once you have chosen an answer.
Fill the gap
In a man page, you leave with the key .
In a man page, you leave with the key ….
Check works once you have typed an answer.
Next up: your first real incident. The deploy on web-01 hangs.
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.
Cards
-
Card 1 of 3
Tap the card or press Space to turn it over.
-
Card 2 of 3
Tap the card or press Space to turn it over.
-
Card 3 of 3
Tap the card or press Space to turn it over.
End of the lesson
Still open: 4 exercises, 3 quiz questions
What you can do now: man ls, history
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: done
- 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
- Lesson 13: open
- Lesson 14: open
- Lesson 15: open
- Lesson 16: open
- Lesson 17: open
- Lesson 18: open
- Lesson 19: open
- Lesson 20: open
- Lesson 21: open
- Lesson 22: open
- Lesson 23: open
- Lesson 24: open
- Lesson 25: open
- Lesson 26: open
- Lesson 27: open
- Lesson 28: open
- Lesson 29: open
- Lesson 30: open
- Lesson 31: open
- Lesson 32: open
- Lesson 33: open
- Lesson 34: open
- Lesson 35: open
- Lesson 36: open
- Lesson 37: open
- Lesson 38: open
Cheat sheet
-
man <command>the manual page, q ends it -
man -k <word>search the manual by keyword, real server only -
<command> --helpshort overview of the options -
type <name>what the shell would run -
historynumbered list of your commands
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 19 KB)
- View as image (PNG, 55 KB)