Mission 17 of 30

History and Command Recall

Use history to recover useful commands without erasing more than intended.

Reuse previous commands, search history, and learn which history shortcuts require caution.

30–40 min Week 3 · Productivity, storage, packages, networking Ubuntu terminal
Your outcome: You stop retyping long commands and start using recall tools carefully.
Practice inside ~/linux-practice. Check your setup before you begin. Prerequisite: Aliases and Command Shortcuts .

What you’ll practice

  • View command history
  • Repeat safe commands
  • Understand history expansion risks

The mental model

  • The shell remembers commands.
  • Ctrl+R searches backwards interactively.
  • History expansion runs commands, so read before pressing Enter.

Try it in your terminal

View history

Read-only system view

Shows recent commands.

Run from ~/linux-practice

history 10

Repeat simple commands

Caution

Repeats the previous harmless echo command.

Run from ~/linux-practice

echo 'safe repeat demo'
!!

History clearing example

Caution

Clears current shell memory history. Explanation only for most learners.

Run from ~/linux-practice

history -c

Put it into practice

  1. Run three echo commands, then use history 5.
  2. Try Ctrl+R and abort with Ctrl+G if you do not want to run anything.

Check your result

A useful prior command can be found without clearing history.

Common mistakes

  • You type `!42`, press Enter, and watch the wrong command execute. Always run `history 42` first to see what command 42 actually is. Read before you run.
  • You type `history -c` to clear one bad command and lose your entire history. History clearing is all or nothing. If you want notes, write them to a file instead.

Check your understanding

Explain these in your own words. If you’re unsure, revisit the examples before moving on.

  1. What shortcut searches history?
  2. Why is !number a caution feature?

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.