Understanding Ctrl + Z and Ctrl + C in the Linux Terminal

Prateek Srivastava
3 min readOct 21, 2023

--

The Linux terminal is a powerful tool for interacting with your computer. To make the most of it, it’s essential to understand various keyboard shortcuts and commands. Two common keyboard shortcuts you’ll encounter in the terminal are Ctrl + Z and Ctrl + C. While they both involve the Control key and the letter Z or C, they serve different purposes. In this blog, we’ll explore these shortcuts, their functions, and provide examples of when and how to use them.

Ctrl + Z: Suspending a Process

Ctrl + Z is used to suspend a running process in the terminal. This means that you temporarily pause the execution of a program and move it to the background, allowing you to continue using the terminal. It’s useful when you want to halt a process without terminating it. Here’s how to use it:

Example 1: Pausing a Long-Running Process

Let’s say you’re compressing a large file using the gzip command, and it's taking longer than expected. You can press Ctrl + Z to pause the compression process and return to the terminal prompt. This doesn't terminate the gzip command; it simply stops it temporarily.

$ gzip -9 largefile.txt
[Press Ctrl + Z]
[1]+ Stopped gzip -9 largefile.txt

Now, the gzip process is paused and can be resumed later using the fg (foreground) command:

$ fg

Example 2: Running a Process in the Background

You can also use Ctrl + Z to start a command in the background. For instance, you can run a command like this:

$ my_long_running_command &

However, if you forget to use the ampersand (&) to run it in the background, you can press Ctrl + Z to suspend it and then type bg (background) to resume its execution in the background.

Ctrl + C: Interrupting a Process

Ctrl + C, on the other hand, is used to forcefully terminate a running process. When you press Ctrl + C, the terminal sends an interrupt signal (SIGINT) to the process, causing it to stop immediately. It’s a quick way to exit a process or command.

Example: Stopping an Unresponsive Program

Imagine you’re running a program that becomes unresponsive or is stuck in an infinite loop. You can use Ctrl + C to interrupt the program and return to the terminal prompt.

$ ./my_program
[Press Ctrl + C]
^C

The ^C represents the interrupt signal. It effectively ends the execution of my_program.

Conclusion

In the Linux terminal, Ctrl + Z is for suspending processes, allowing you to resume them later, while Ctrl + C is for forcefully terminating processes. Understanding when and how to use these shortcuts can make your command-line experience more efficient. Whether you need to pause a long-running task, manage background processes, or stop an unresponsive program, these keyboard shortcuts are essential tools in your Linux journey.

🙏 Thank You for Reading!

Your time and attention mean a lot to us. We greatly appreciate your engagement with our content and would love to hear your thoughts and ideas. Let’s stay connected and continue our journey through the digital world together! 🌐📚💡

Let’s Stay in Touch 🪂

Connect with us on: LinkedIn, Instagram

--

--

Prateek Srivastava
Prateek Srivastava

Written by Prateek Srivastava

Motivated and innovative professional with 6 years of versatile experience spanning Site Reliability Engineering (SRE) and Research & Development (R&D).