Shutdown, restart, and session recovery
On this page
A guide says to run cat followed by a file name. You type cat, press Enter too early, and the terminal shows this:
learner@rootvolt:~$ catThe cursor waits on the empty line below. No message, no prompt. A minute later, nothing has changed. Is the VM frozen? Should you close the window, or switch the VM off?
Neither. By the end of this lesson, you can tell a command that is running from one that is waiting for you, and get the prompt back from both. You can also recover a lost terminal window or a stuck desktop, and turn the VM off without risking its disk.
Before you start
Section titled “Before you start”- Regular users, root, and privileged actions (B03.3). Open a terminal in
rootvolt-lab. The commands run in your home directory, the~in the prompt. - This lesson runs
sleep,cat, andecho. Type each one exactly as shown; module B04 explains how commands are built. None of them changes a file.
The terminal output was captured on the course’s lab system, which shows the same prompt. The screens were captured in Ubuntu 24.04.4 LTS in VirtualBox 7.2.18 on a Windows host.
A command that is still running
Section titled “A command that is still running”Bash shows the prompt “when it is ready to read a command” (lesson B03.2). While a command runs, Bash waits for it, and the prompt comes back when the command ends.
sleep shows this clearly. Its manual page says it does one thing: “Pause for NUMBER seconds”. Run this:
sleep 3For three seconds, the line below stays empty. Then the prompt returns:
learner@rootvolt:~$ sleep 3learner@rootvolt:~$Now run sleep 300, which would take five minutes, and press Ctrl+C. Guess first: what will the screen show?
Run it, then compare with your guess
learner@rootvolt:~$ sleep 300^Clearner@rootvolt:~$^C is the key you pressed. sleep stopped at once, long before the five minutes were over. Ctrl+C stops a command that is already running. In lesson B04.2, the same key also discards a line you are still typing.
Ctrl+C sends an interrupt to the running command, and sleep stops. Module B13 explains processes and the ways to stop them.
learner@rootvolt:~$ sleep 3learner@rootvolt:~$ sleep 300^Clearner@rootvolt:~$ whoamilearnerlearner@rootvolt:~$ Steps (9)
- Type
sleep 3— sleep waits 3 seconds, then ends by itself - Press Enter — After 3 seconds, the prompt comes back
- Type
sleep 300— This one would wait 5 minutes - Press Enter — sleep is running: no output, no prompt
- Press Ctrl + C — Ctrl+C stops the running command; the prompt returns
- Type
whoami— Bash is ready for the next command - Press Enter
- Output:
learner - Ctrl+C stopped sleep 300; the prompt came back, and the next command ran at once.
In words: sleep 3 ends by itself, and the prompt returns. sleep 300 shows no output and no prompt while it runs. Ctrl+C prints ^C and stops it. whoami then runs at once and prints learner: Bash is ready again.
A command that waits for you
Section titled “A command that waits for you”Back to the opening. Run cat with nothing after it:
catUnlike sleep, cat is not counting seconds: it waits for you. Its manual page says that “With no FILE” it reads “standard input”, which is what you type, and gives cat alone as the example “Copy standard input to standard output”.
Type Lab notes and press Enter. Guess first: what appears?
Run it, then compare with your guess
The line appears twice: once as you typed it, and once below it, printed back by cat. Then cat waits for the next line. It answered you, so it was waiting, not frozen.
There are two ways out.
Ctrl+D ends the input. Press it at the start of a line, right after Enter. The termios manual page calls Ctrl+D the “End-of-file character”: cat sees that the input has ended and finishes normally. Nothing appears for the key; the prompt returns:
learner@rootvolt:~$ catlearner@rootvolt:~$Ctrl+C stops the command, as it stopped sleep:
learner@rootvolt:~$ cat^Clearner@rootvolt:~$Use Ctrl+D when you are done typing input. Use Ctrl+C when the command should not be running at all, as in the opening. Then type the command again, with the file name.
An unfinished line
Section titled “An unfinished line”Bash itself can wait, too. Type this line, with a double quote before the text and none after it, and press Enter:
echo "Lab notesecho prints its text, as in lesson B02.4. But the quote was opened and never closed, so Bash waits for the rest and shows >, which its manual calls the “secondary prompt string”. Press Ctrl+C to abandon the whole line:
learner@rootvolt:~$ echo "Lab notes> ^Clearner@rootvolt:~$Nothing ran, and the normal prompt is back. When you see > instead of your prompt, look for a quote you did not close. Module B08 explains quotes.
Closing a terminal window
Section titled “Closing a terminal window”The commands you start in a terminal window run inside it, and closing the window ends them. Run sleep 300 again and click the window’s ×. In the tested VM, GNOME Terminal asked first:

sleep 300is running: no prompt follows it.- The × button that closes the window.
- Close this terminal?: “There is still a process running in this terminal. Closing the terminal will kill it.”
- Cancel keeps the window and the command.
- Close Terminal ends both.
A process is a running program (lesson B03.2), and to kill it is to end it. Here it is only sleep, so click Close Terminal.
To recover, press Ctrl+Alt+T: a new window, a new Bash, a new prompt. What was in the closed window is gone: its output, what you had typed, and the commands that ran there.
Power off and restart from Ubuntu’s menu
Section titled “Power off and restart from Ubuntu’s menu”To turn the VM off, shut Ubuntu down from inside, as in lessons B02.3 and B02.4: open the system menu, click the power button, and choose Power Off… (lesson B03.1). Ubuntu asks you to confirm:

- The title, Power Off.
- The countdown: “The system will power off automatically in 60 seconds.”
- Cancel keeps the system running.
- Power Off turns it off now.
Restart… opens the same dialog with the title Restart, the text “The system will restart automatically in 60 seconds.”, and the buttons Cancel and Restart. The VM turns off and starts again, back to the login screen. As with Log Out in lesson B03.1, doing nothing is not cancelling: when the countdown ends, it happens.
Either way, Ubuntu shuts down by itself: it ends your session, closes the programs still running, and finishes its work on the disk before the power goes off.
Closing the VM’s window
Section titled “Closing the VM’s window”VirtualBox offers another way: the × of the VM’s window on the host. The VirtualBox manual says it then “asks you whether you want to save or power off the VM”. In the tested VM:

- Save the machine state. The manual: VirtualBox “freezes the virtual machine by completely saving its state to your local disk”, and the next start “continues exactly where it was left off”. This course does not use it.
- Send the shutdown signal. The manual: “the same effect as if you had pressed the power button on a real computer”, which “should trigger a proper shutdown mechanism from within the VM”. It asks Ubuntu to shut down by itself. In the tested VM, Ubuntu powered off without showing its own dialog.
- Power off the machine. The manual: “This is equivalent to pulling the power plug on a real computer without shutting it down properly.” It “can potentially cause data loss or an inconsistent state of the guest system on disk”.
- Restore current snapshot ‘clean-install’. Ticked, powering off also returns the VM to that snapshot, and “any changes made since the previous snapshot was taken will be lost”. It was unticked in testing; leave it so.
- OK does what is selected. In the tested VM, Power off the machine was already selected when the dialog opened.
To end a session, use Ubuntu’s Power Off…, not this dialog. Use Send the shutdown signal when you cannot reach Ubuntu’s menu. Keep Power off the machine for a guest that cannot shut down by itself. Lesson B02.3 used it when the installer started again: the VM was running the installer from the image, not your system, and no work of yours was open. It is a way out, not a habit.
When the desktop stops responding
Section titled “When the desktop stops responding”If clicks and keys change nothing on the desktop, first check whether Ubuntu is still running underneath. Press Host+F3, the right Ctrl key and F3, as in lesson B03.2. The text console does not need the desktop: if rootvolt login: appears and you can log in, Ubuntu is running, and only the desktop is stuck. Log out with exit, press Host+F2, and give the desktop a minute.
If it is still stuck, close the VM’s window and choose Send the shutdown signal. Choose Power off the machine only if the guest does not respond to that either, or if the console did not appear at all.
Mistakes to recognize
Section titled “Mistakes to recognize”Ctrl+C to copy. You select text while a command runs and press Ctrl+C. The screen shows ^C and the prompt: you stopped the command. In GNOME Terminal, copy is Shift+Ctrl+C, and paste is Shift+Ctrl+V.
One Ctrl+D too many. At Bash’s own prompt, on an empty line, Ctrl+D ends Bash itself: the bash manual page says that, unless IGNOREEOF is set, “EOF signifies the end of input to the shell”. Ubuntu’s default settings do not set it. If your window closes or shows no prompt, open a new one with Ctrl+Alt+T.
OK without reading the selection. You close the VM’s window and press OK out of habit. With Power off the machine selected, as in testing, that pulls the power cable. Read which option is filled before you click.
Close Terminal with unsaved work. The warning says the running process will be killed. A program that holds unsaved work, such as a text editor (module B07), loses it. Click Cancel, save, and quit the program first.
Good to know
Section titled “Good to know”A saved state takes disk space. It includes the VM’s memory, and the manual says a memory state file “can be as large as the memory size of the VM”: up to 4 GB for the course VM.
Try it yourself
Section titled “Try it yourself”Goal: Get a working prompt back three times, in three different ways, then restart the VM safely.
- Run
sleep 900. Get the prompt back without closing the window. - Run
cat, typechecked the snapshot, and press Enter. Then endcatso that it finishes normally instead of being stopped. - Run
sleep 900again. This time close the window, and get to a working prompt. - Restart the VM from Ubuntu’s menu.
Expected: ^C and the prompt; your line printed back, then the prompt with no ^C; a warning before the window closes, then a fresh prompt in a new window; the login screen after the restart.
Hint
One key stops a command; another tells it that the input has ended. A new terminal window opens with the shortcut from lesson B02.3.
Solution
- Press Ctrl+C.
catprintschecked the snapshotagain. Press Ctrl+D at the start of the next line:catends normally, so no^Cappears.- Click the window’s ×, read Close this terminal?, and click Close Terminal. Press Ctrl+Alt+T for a new window.
- Open the system menu, click the power button, choose Restart…, and click Restart. Log in again.
- The prompt means Bash is ready. Without it, a command is running or waiting. Ctrl+C stops a running command; to copy in GNOME Terminal, use Shift+Ctrl+C.
catwith no file name waits for input: Ctrl+D at the start of a line ends it. A>prompt means Bash waits for the rest of a line; Ctrl+C abandons it.- Closing a terminal window ends what runs in it. Ctrl+Alt+T opens a new one; the old one’s contents are gone.
- Power off and restart from Ubuntu’s menu, so that Ubuntu shuts down by itself.
- In VirtualBox’s Close dialog, check the selection before OK: Power off the machine pulls the power cable. If the desktop is stuck, check the console with Host+F3, then try Send the shutdown signal.
Next, in Practice: Your First Linux Session, you use everything from this module in one task.
Further reading
Section titled “Further reading”All sources were checked on 4 November 2026.
- Oracle VirtualBox User Guide, release 7.2, Working with Virtual Machines: section Closing or Saving a VM, on the three ways to close a VM; and section Snapshots, on the size of a memory state file.
- GNOME Help: Log out, power off or switch users, section Power off or restart.
- GNOME Terminal Help: Copy and paste text, on Shift+Ctrl+C and Shift+Ctrl+V.
- Ubuntu 24.04 manual pages: sleep(1); cat(1), with the example
catalone; termios(3), onVINTR(Ctrl+C) andVEOF(Ctrl+D); and bash(1), section SIGNALS, on Ctrl+C while Bash waits for a command, and section Shell Variables, onPS2andIGNOREEOF. - GNU Bash Reference Manual: Signals.