If you’re trying to copy text from the Linux terminal, pressing Ctrl + C might not give you the results you expect—it’s designed to stop commands, not copy text. Instead, to copy from the terminal, use Ctrl + Shift + C. This shortcut ensures you can easily select and copy output or commands without disrupting terminal processes.
In this guide, we’ll explain how to copy or paste text, also how to undo or redo text in the Linux terminal, this will streamline your file management tasks, including extracting and handling files efficiently.
What is Ctrl + C and Ctrl + Z in the Linux Terminal
The Linux terminal is a powerful tool for managing tasks, but shortcuts like Ctrl + C and Ctrl + Z can seem confusing if you're new to it. Here's what they do:
- Ctrl + C: This shortcut is used to stop a running process in the terminal. For example, if you've started a program or command that's taking too long, pressing Ctrl + C will immediately terminate it. Think of it as a way to "cancel" the operation.
- Ctrl + Z: This shortcut pauses a running process and sends it to the background. The command doesn’t stop completely—it’s just paused. You can bring it back to the foreground later using the
fg
command.
These shortcuts are particularly useful for managing tasks efficiently. For instance, if you're extracting a large file or running a script and need to pause it momentarily, Ctrl + Z is your friend. If you accidentally run a wrong or endless command, Ctrl + C saves you from having to wait.
Ctrl + C in Linux Terminal
On a Linux terminal (or other command-line interfaces such as macOS Terminal or Git Bash), Ctrl+C is a shortcut key that kills a running command or program immediately. It is like the "Stop" button on a TV remote control—it stops whatever the terminal is currently doing and gives you control again.
Example:
- You’re running a command like ping google.com to check your internet connection, but it keeps going forever. Press Ctrl+C to stop it.
- You accidentally start a script that’s looping endlessly. Ctrl+C is the good option.
How Ctrl+C Works
When you press Ctrl+C, you're actually sending a special message known as the SIGINT signal (short for "Signal Interrupt") to the currently running program (also referred to as a process). This signal instructs the program to stop and exit.
- The majority of programs (such as ping, top, or scripts) will terminate normally.
- Some resistant programs (such as background services) may refuse to do so.
Example with a Simple Command:
ping google.com # This sends endless network requests
Press Ctrl+C : The ping
command stops instantly. You can see in the image ^C it means that user press the ctrl+c
What Is the SIGINT Signal?
The SIGINT signal is one of numerous signals the Linux operating system uses to talk with processes. Consider signals like text messages between the system and a program. SIGINT reads, "Could you please halt now?" The majority of applications are written to watch for SIGINT and shut down gracefully if it receives SIGINT. A few other signals include:
- SIGTSTP (sent by Ctrl+Z): Pauses a process, letting you resume it later.
- SIGKILL: Forces a process to stop instantly, with no chance to save work (used with the kill -9 command).
SIGINT is more friendly than SIGKILL since it provides an opportunity for the program to clean up, such as closing files or saving data, before termination.
Where Does the Data Go When You Press Ctrl+C
On pressing Ctrl+C, the process terminates and its data is handled as follows:
1. Memory is cleared: The process is taken out of the computer's memory (RAM). Any temporary information, such as variables or unsaved work, is typically gone unless the program wrote it to a file prior to being stopped.
2. Saved data stays: If the process was writing to a file (such as a download or log), the file retains whatever was written prior to Ctrl+C. For example:
- If you were downloading a file using wget and interrupted it with Ctrl+C, the partially downloaded file remains on your disk. Utilities such as wget usually allow you to resume the download later.
3. No undo buffer: While Ctrl+C in a text editor (which may copy text to a clipboard) may save a copy of the work done, Ctrl+C in the terminal does not save a copy of the process's work. When the process is interrupted, its unsaved work is lost.
4. Output stops: If the operation was outputting to the terminal (e.g., ping printing response times), that output stops right away. You can't restore the output unless it was redirected to a file (e.g., with ping google.com > output.txt).
Can You Recover Data After Ctrl+C
Unfortunately, Ctrl+C is a one-way stop sign—there's no built-in method to "undo" it or restore the process's unsaved work. Here's why:
- Process is terminated: When SIGINT terminates the process, it's removed from memory, and its state (such as progress or calculations) is lost.
- No snapshot: The terminal retains no history of the process's data, compared to an editor's undo mode.
- Partial data might remain: If the process was writing to a file, look at the file for what it saved prior to Ctrl+C. For example, a partial download or log file could still prove to be valuable.
Ctrl + Z in Linux Terminal
In a command-line interface (like Linux Terminal, macOS Terminal, or Windows Command Prompt with tools like Git Bash), Ctrl+Z doesn’t undo anything—it pauses a running program and sends it to the background. Think of it like putting a movie on pause: the program stops running but stays “asleep” in the background, waiting for you to decide what to do next.
For example, if you're running a command or application like a text editor (nano
) and want to temporarily pause it without losing progress, pressing Ctrl + Z will suspend the process. The terminal will display a message like this:
[1]+ Stopped nano
The [1]+
indicates the job number, and "Stopped" means the process is paused. You can resume the process using the following commands:
fg
: Brings the process back to the foreground to continue where you left off.bg
: Resumes the process but keeps it running in the background.
This shortcut is especially useful when multitasking in the terminal, letting you pause one task while working on another without terminating anything.
How Does Ctrl+Z Work
So when the user press the Ctrl+Z they are sending a special signal called SIGTSTP (Signal to Suspend) to the running program which is also known as process. Basically this signals tell the operating system to suspend the process means that it stops running but stays in memory, ready to be resumed later.
1. You Run a Command: Lets say user use the sleep 1000 command in the terminal. This command makes the terminal “sleep” (do nothing) for 1000 seconds.
2. You Press Ctrl+Z: So whenever you press the Ctrl+Z in the terminal they sends the SIGTSTP signal to the sleep 1000 process, that is they are saying to the program, "Hey, take a nap!". The process gets suspended and goes to the background. The terminal displays a message like:
[1]+ Stopped sleep 1000
3. The Terminal is Free: Now you may use the terminal to execute another command, such as listing files with ls or executing another job. The stopped process remains in memory, at your beck and call.
How to Restart a Paused Ctrl+Z Process in Linux
When you’re ready to restart a process you paused with Ctrl+Z, Linux gives you two simple commands to choose from: fg and bg
1. fg (Foreground) command
The fg command brings the paused process back to the foreground, meaning it takes over the terminal again and picks up right where it left off.
After pausing a process with Ctrl+Z, just type:
fg
The process wakes up and continues running in the terminal.
2. bg (Background) command
The bg command tells the paused process to keep running in the background, so it continues working without taking over the terminal. It’s like playing music in another room—you can still do other things while it’s going.
After pausing a process with Ctrl+Z, type:
In this if you press the ctrl+c or ctrl+z the process is still going but you can run any command if the process is going on. In the below image you can see that user type the pwd command in between running process:
Handling Multiple Paused Processes
What if you’ve paused more than one process? Linux assigns each paused process a job number (like [1], [2], etc.). You can see all paused processes by typing:
jobs
Here you can see that there are two process which is pause. To resume a specific process, add its job number to the fg or bg command:
Resume job [2] in the foreground:
fg %2
Run job [1] in the background:
bg %1
Where Does the Data Go When You Press Ctrl+Z?
When you press Ctrl+Z, the process and its data don't vanish—they're still in the computer's memory (RAM). The operating system suspends the process:
- Data is preserved: If the process was downloading a file, the partially downloaded file remains on your disk, and the progress of the download is stored in memory.
- No data is lost: The operation is simply "paused," so everything its work (such as variables, progress, or open files) is preserved unless the machine restarts or the operation is cancelled.
- No undo buffer: Unlike Ctrl+Z in a text editor (which stores changes in an undo history), Ctrl+Z in the terminal doesn’t create a backup or snapshot. It simply pauses the process in its current state.
What Happens to the Work?
The work (like a file being downloaded or a script running) stays exactly where it was when you pressed Ctrl+Z. For example:
- Suppose you were downloading a 1GB file and had completed 500MB. The 500MB file remains on your disk, and the download operation retains where it left off.
- Suppose you were executing a script that was processing information. The script stops executing but retains all its progress in memory.
But if you shut down the computer or terminate the process (later, we'll discuss more about that), the suspended process vanishes, and you could lose unsaved work. For example, a stopped download would have to begin anew unless the download utility allows resuming.
Can You Recover Work After Ctrl+Z
Unlike Ctrl+Z in a text editor, where you "undo" modifications by drawing from an undo history, Ctrl+Z in the terminal has no undo. Instead, it's a matter of pausing and continuing. Here's the information you need:
- No undo history: The terminal doesn't keep a "backup" of what the process was up to before you paused it. The process is just suspended in its present state.
- Resuming is recovery: Using fg or bg is how you "recover" your work. The process resumes right where it stopped, with all data preserved.
- Losing work: If you close the terminal by mistake or reboot the machine, the suspended process is lost, and you may lose unsaved work. For instance, a suspended download would have to start over unless the tool (such as wget) allows resuming from a partial file.
Also Check:
Conclusion
Mastering shortcuts like Ctrl + C and Ctrl + Z in the Linux terminal can significantly improve your efficiency and control over processes. While Ctrl + C is your go-to for stopping commands that are running too long or behaving unexpectedly, Ctrl + Z lets you pause tasks and resume them later without disruption.
Additionally, if you’re working with text in the terminal, remember that copying requires Ctrl + Shift + C, not just Ctrl + C. Understanding these shortcuts makes managing tasks and file operations—like unzipping files or running scripts—much easier and less time-consuming.
Similar Reads
How to Clear the Terminal History in Linux
The Linux Terminal stores every command you execute in a history file like .bash_history for Bash or .zsh_history for Zsh, making it convenient to access previous commands. However, this history can become a privacy or security issue, especially when dealing with sensitive tasks or working on shared
6 min read
What is a Controlling Terminal in Linux?
Most of you should be aware of the Terminal in Linux which is a Command-line Interface. However, there are very few individuals who know about the existence of Linux Controlling Terminal.If you are a System Administrator, or a user who interacts with Linux Systems, then knowing about Controlling the
5 min read
How to Install and Use Alacritty Terminal Emulator in Linux?
Alacritty is a cross-platform terminal emulator with GPU acceleration. It's a terminal emulator for OpenGL written in the Rust programming language. Alacritty is the fastest and lightest Terminal emulator in nature, thanks to its OpenGL renderer and high throughput parser. Alacritty Terminal emulato
2 min read
How to Make Custom Commands for Linux Terminal?
With commands, users can communicate with the operating system via the Linux terminal, a handy tool. Although the terminal has several pre-defined commands, you can improve productivity and optimize processes by writing your custom commands. This article explains how to write and use custom commands
4 min read
How to Create a File in the Linux Using the Terminal?
In this article, we will learn to create a file in the Linux/Unix system using the terminal. In the Linux/Unix system, there are the following ways available to creating files. Using the touch commandUsing the cat commandUsing redirection operatorUsing the echo commandUsing the heredocUsing the dd c
4 min read
How to Open Terminal in Linux?
The Shell or Command Prompt are common name for the Linux Terminal. The terminal was designed as a Linux File Browser, and this function is still carried out using it. You may traverse your files and undo changes made by using the Terminal as a File Browser. However, the very first step will be to O
4 min read
How to zoom in and zoom out terminal console in linux
Linux is a Debian-based Operating system used by many professionals and other people for various purposes. Mainly Linux is used for Penetration testing and Vulnerability assessment. Windows systems often interact with GUI (graphical user interface) but in Linux, we use a terminal console more to int
7 min read
How to copy a file's content from Linux terminal?
This article shows the alternative method to copy the content of the file onto the clipboard, via the Linux terminal. In OSX, the commands pbcopy and pbpaste are available by default. Thus, to copy a file onto the clipboard via OSX terminal, type: pbcopy < 'path of the file' Since, in U
2 min read
How To Compile And Run a C/C++ Code In Linux
C Programming Language is mainly developed as a system programming language to write kernels or write an operating system. C++ Programming Language is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance. In this article, we will be compiling and exe
4 min read
How to Run a File in Linux
The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window. One common task you'll often need to do is run a file, whether itâs a script, a compiled program, or even a text file. In this article,
6 min read