terminal.cab

Linux Basics Lesson 3 of 38

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

Help and history

7 minutes

Learning goals

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:

  • /WORD search in the page, n for the next match
  • -k WORD on a real server, search all short descriptions; not in this simulator yet

Example:

man ls | head -n 5
NAME
       ls - lists what is in a directory

SYNOPSIS
       ls [OPTION]... [FILE]...

in the glossary: man

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:

  • !! run the last command again
  • Ctrl-R search backwards as you type

Example:

hostname
web-01
whoami
lerner
history
    1  hostname
    2  whoami
    3  history

in the glossary: history

Practice

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Predict the output

Command

type ls

Before the command, in your home folder ~

  • ~/.bashrc
  • ~/.profile
  • ~/.secret
  • ~/Documents/
  • ~/logs/
  • ~/notes.txt
  • ~/projects/
  • ~/archive/
What does type ls print?

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

  1. Question 1 of 3You want to run a long command from yesterday again and remember part of it. What is fastest?

    Check works once you have chosen an answer.

  2. Question 2 of 3What does help know about?

    Check works once you have chosen an answer.

  3. Question 3 of 3You only want the short overview of a command's options. What do you try first?

    Check works once you have chosen an answer.

Cards

  1. Card 1 of 3

    Tap the card or press Space to turn it over.

  2. Card 2 of 3

    Tap the card or press Space to turn it over.

  3. 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

Next: lesson 4, Saturday, 17:03, the deploy hangs (8 min)

What you can do now: man ls, history

+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
  13. Lesson 13: open
  14. Lesson 14: open
  15. Lesson 15: open
  16. Lesson 16: open
  17. Lesson 17: open
  18. Lesson 18: open
  19. Lesson 19: open
  20. Lesson 20: open
  21. Lesson 21: open
  22. Lesson 22: open
  23. Lesson 23: open
  24. Lesson 24: open
  25. Lesson 25: open
  26. Lesson 26: open
  27. Lesson 27: open
  28. Lesson 28: open
  29. Lesson 29: open
  30. Lesson 30: open
  31. Lesson 31: open
  32. Lesson 32: open
  33. Lesson 33: open
  34. Lesson 34: open
  35. Lesson 35: open
  36. Lesson 36: open
  37. Lesson 37: open
  38. Lesson 38: open
1 of 38

Next: lesson 4, Saturday, 17:03, the deploy hangs (8 min) That's enough for today

Path complete

You finished all 38 lessons of Linux Basics.

Back to the path

Cheat sheet

The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.