Linux Labs

First steps / Stage 3 of 15

Working comfortably in the terminal

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 8 · on a machine · 3 min

Interrupt a command

A command runs longer than you need, and the prompt does not come back. One key combination brings it back.

While a program runs, there is no prompt: the shell waits for the program to finish. That alone does not mean anything froze — the program may be computing, waiting for data, or waiting for a key.

Ctrl+C sends the running program an interrupt signal. Usually the program exits right there, and the shell prints the prompt. sleep 30 does nothing but wait thirty seconds — start it and press Ctrl+C before it ends:

bash
sleep 30

An interrupt stops the program wherever the signal caught it.

Note

In the terminal Ctrl+C interrupts a program and copies nothing. To copy, select the text with the mouse and press Ctrl+Insert, or pick Copy in the right-click menu. To paste, use Shift+Insert or Paste in the same menu.

Check yourself 1 question

A command is copying a hundred files into the backup directory. At the fortieth file you press Ctrl+C. What is in backup?

  • Copying leaves the source files alone, and an interrupt does not change that: they stay where they were.

  • The interrupt signal usually ends the program right away, without finishing the job. Backup holds as many files as it managed to copy.

  • An interrupt stops the program and does not delete files already written: what was copied before Ctrl+C stays in backup.

Ctrl+C stops the program where it was and rolls nothing back. The files copied so far stay in backup, so after an interrupt you check the result.

Key points

  • No prompt means a program is running. Ctrl+C interrupts it and brings the prompt back.
  • Ctrl+C rolls nothing back: what was done before the interrupt stays.
Ubuntu 24.04
Loading…