In Linux, Ctrl+Z isn’t just a shortcut—it’s the built-in way to pause or undo your last command in the terminal, giving you back control over what’s happening on your system. No extra software or typing magic required. If you’ve accidentally run a destructive command or need to re-enter a prompt after an error, this simple key combo saves you minutes. The steps are identical across most Linux distros (Ubuntu, Fedora, Arch, etc.), and it even works on systemd-based systems like Wayland. Want to recover your last terminal session, restore a deleted file, or save a broken process? Read on—this guide covers all the precise ways to use Ctrl+Z properly.
What You'll Need
- Your Linux terminal (open it with Ctrl+Alt+T in most desktop environments)
- A command that was already executed, or a prompt where you’re ready to re-enter text
- Basic familiarity with Linux terminal commands (optional, but helpful)
Step-by-Step
- Press
Ctrl+Zwhile inside a running commandThe key combination sends the command to the background (if it’s running) or pauses it in the foreground. The terminal will briefly show a prompt like
Stoppedor[1] 1234(the job ID) before returning to the shell.What it really does: It sends the process to the "background" job list (job queue), allowing you to resume it later with
fgorjobs. If the command was already complete, it’ll just pause execution at the last line. - Use
jobsto see your paused processesTo list all jobs (including paused ones), run:
jobsYou’ll see output like:
[1] + 2345 stopped tail -f /var/log/syslog [2] - 2346 running ping 8.8.8.8The number (e.g., 1 or 2) is the job ID. The state tells you if it’s stopped (
stopped) or running (running). - Resume a stopped job with
fgTo bring a stopped job back to the foreground, use:
fg %job_idExample:
fg %1This will resume
tail -f /var/log/syslogimmediately where it left off.
Undoing Commands Without Backgrounding
- Ctrl+Z with no backgrounding (for incomplete operations)
If you’ve typed a command but haven’t hit Enter yet,
Ctrl+Zwill simply pause the prompt. The command won’t be executed, and you can re-enter it entirely fresh:Ctrl+Z[something you typed]Ctrl+Z[re-type your full command]This is how you "undo" a partially typed command without losing progress.
Common Mistakes
- Assuming Ctrl+Z works on all commands
Not all Linux commands respect
Ctrl+Z. For example, GUI applications, scripts that run as root, or commands from non-interactive shells (like cron jobs) may ignore it. IfCtrl+Zdoesn’t pause anything, your command might be using a different signal or running in a mode that ignores interruptions. - Forgetting the job ID
If you’ve run multiple commands and only see
jobsshow one job, check if you accidentally ran multiple commands in sequence without proper line breaks. If the job list is empty, you may need to run the command again carefully. - Using Ctrl+Z instead of Ctrl+C
Ctrl+Cstops commands immediately (sends SIGINT), whileCtrl+Zpauses them. If you want to kill a process entirely, useCtrl+Cfirst, then usekill -9if necessary. - Pair Ctrl+Z with
fgfor efficiencyAfter pausing a long-running command, use
fgto resume it instead of running the entire command again. This is especially useful for log monitoring (tail -f) or network scans. - Use
killto free up resourcesIf a stopped job consumes unnecessary resources, run:
kill -0# Check if job exists kill -9# Forcefully terminate Warning: Use
-9(SIGKILL) only if the job is unresponsive. Otherwise,killwith-15(SIGTERM) is safer. - Combine with
tmuxorscreenfor sessionsIf you’re using a terminal multiplexer like
tmux,Ctrl+Zworks just like in a regular shell (as long as the multiplexer isn’t in detached mode). Detached sessions can be resumed withtmux attach. - Check for interactive shells
Some shells (like
zshwith certain plugins) may add extra behavior. TestCtrl+Zin a clean session to confirm it works as expected. - Restart your terminal
Sometimes the shell simply needs a fresh start. Close and reopen your terminal window.
- Check if the shell is interactive
Run this command to test if the shell is interactive:
echo $SLOTIf it returns a number (e.g., 0), your shell is likely interactive. If it returns nothing or an error, you may be in a non-interactive shell (like cron or a script).
- Run
sttyto verify signal handlingTest if your shell respects
Ctrl+Zby running:stty -a | grep -i sigzIf you see
sigzin the output, your shell should handleCtrl+Zproperly. If not, your shell may be configured to ignore it. - Switch to a different shell
If the issue persists, try another shell (e.g.,
bashinstead offish). Some shells have conflicting signal handling. - Check for system-wide signal blocking
Run this to see if any processes are blocking signals:
cat /proc/*/status | grep -E 'Pid|Sigs'Look for entries like
Sigswith blocked signals. If you see unusual blocking, you may need to adjust your system’s signal handling. - Recover deleted files with
findandrestore - Use
journalctlto recover systemd logsIf you’ve lost system logs (often lost when rebooting), try:
journalctl --no-pager -n 50This shows the last 50 log entries. If you modified a service, check its logs with
systemctl status. - Restore permissions with
chmodandchown - The command is running in a non-interactive shell (like a cron job).
- Your shell is configured to ignore
Ctrl+Z(check withstty -a). - You’re using a GUI application (not a terminal command).
Tips
Troubleshooting
If Ctrl+Z isn’t working as expected, try these steps in order:
Undoing File Deletions or Permissions
Ctrl+Z alone won’t recover deleted files or permission changes. For those cases, use:
First, check if you have a restore group (common on Debian/Ubuntu systems):
groups
If you see restore, run:
sudo find / -type f -delete -path "*deleted*" | sudo restore
Warning: This is destructive. Test on a backup first.
If you accidentally changed file permissions, you can restore them manually:
sudo chown -R $USER:$USER /path/to/directory
sudo chmod -R 755 /path/to/directory
This restores ownership and read/write/execute permissions to the current user.
Frequently Asked Questions
Why doesn’t Ctrl+Z work for me?
If Ctrl+Z doesn’t pause your command, it could be because:
Can I undo a command that’s already completed?
Yes! Simply run the command again. Ctrl+Z doesn’t "undo" completed actions—it only pauses them. To truly "undo" a completed command, you’d need to use version control (like git) or manually restore files.
How do I resume a stopped process after Ctrl+Z?
Use fg %, where job_id is the number shown by jobs. For example:
jobsfg %1
What if I accidentally sent Ctrl+Z to a GUI app?
GUI apps usually ignore Ctrl+Z, but some may pause them (like text editors). If the app froze or paused, you may need to force-quit it from the terminal with pkill or restart it.
Does Ctrl+Z work with Docker containers?
Yes, if the container is running an interactive shell. Once inside a container, Ctrl+Z works like in a regular terminal. To exit, use exit or Ctrl+D.
Can I recover a deleted file using Ctrl+Z?
No. Ctrl+Z only pauses commands, not files. For file recovery, use tools like restore, timestamps, or a file recovery tool like testdisk.