Since it sounds like you're on Linux or other POSIX system---

You're cat command is waiting patiently for input from its standard input, which in this case is the terminal.

If you type Cntrl-D, an End-Of-File condition will be sent to the cat command, and it will finish.

Answer from antlersoft on Stack Overflow
🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › how to stop cat command in linux
How to stop cat command in Linux - nixCraft
March 21, 2024 - To save and quit the cat command, press CTRL+D. You will now return to your shell prompt. A Linux or Unix terminal pager is a command to view (but not modify) the contents of a text file, moving down the file one line or one screen at a time.
Top answer
1 of 7
83

If the file(s) in question contain lots of data, sending the signal can actually get to cat before it finishes. What you really observe is the finite speed of your terminal - cat sends the data to the terminal and it takes some time for the terminal to display all of it.

Remember that it usually has to redraw the whole output window for each line of output (i.e. move the contents of the window one line up and print the next line at the bottom). While there are techniques and algorithms to make this faster than if it was done the straightforward way, it still takes some time.

Thus, if you want to get rid of the output as quickly as possible, hide the terminal window, because then (usually) no actual redrawing takes place. In a graphical environment this can mean either minimizing the window or switching to a different virtual desktop, on the Linux virtual console just switch to another one ((Ctrl +)Alt + Fx).

Also notice that if you ran this over a slow network link (SSH over a GSM connection, for example), you would definitely see much less output before cat is killed by the signal, because the speed of the terminal redrawing wouldn't be the bottleneck any more.

2 of 7
4

Terminal Setup

I reckon this is more to do with the way the terminal is set up, than with any buffering issue. Check the output of stty -a | grep intr, you should have intr = ^C; on the output line if Ctrl-C is enabled at the tty/pty. If it isn't, you can use stty intr ^C to enable it. Add the line to your .tcshrc or .login to make it permanent (or delete the line that changes it in the first place!).

Failing Ctrl-C, you can also try sending SIGQUIT with Ctrl-\. If this doesn't work, again check stty -a | grep quit to see if it is properly set up.

Terminal Emulator Setup

Also check the settings for your terminal emulator (if you are using one), it may be that there is a shortcut set up at this level (maybe for copy or something) and the Ctrl-C does not reach the pty level. A shortcut could also be set up somewhere else in your desktop environment or Window system.

A good test on Linux if you are using a terminal emulator is to switch to a Linux console (Ctrl-Alt-F1), login there and see if the same behaviour occurs. If it doesn't then this suggests the problem lies with your Window system or terminal emulator.

It could be an issue with the delay between data being read from the pty device as suggested by peterph. But if this is the case and you do actually have to wait minutes for the data to be displayed, then surely the terminal emulator is buffering way too much data (or your PC is very slow). The answer would be to find a way to reduce that buffer size in your terminal emulator settings or use a different one.

Extra Tip

Something else worth adding; I usually end up in the runaway cat situation when if I accidentally cat a binary file. The other effect of this can be to screw up your terminal settings (if the binary data happens to match various terminal escape codes which it often does). If tput is installed (usually is by default), you can avoid having to restart with the following command:

tput reset
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › exit-cat-command-without-saving-4175453249
[SOLVED] exit cat command without saving
hello everyone, In past days, sometimes by mistake i run the command, "cat > /etc/passwd" and it get clear when i press CTRL+Z, CTRL+C or
🌐
Quora
quora.com › How-do-you-close-a-cat-command-in-Linux
How to close a cat command in Linux - Quora
Answer (1 of 4): A process running cat will exit when it reaches the end of the last file that it’s concatenating. If you run cat without supplying any filename arguments, then it’s seeking input (performing read() operations) on your terminal. That’s because, in the Unix computing model, a term...
Find elsewhere
🌐
Reddit
reddit.com › r/commandline › how to cancel viewing a file when accidentally cat a non-text file?
r/commandline on Reddit: How to cancel viewing a file when accidentally cat a non-text file?
January 20, 2016 -

I've done a little bit of searching, but I'm having trouble using adequate search terms for this one, since I don't know exactly what to call what's happening.

Every once in a while I will cat a file that can't be shown as text properly, and the cl bugs out trying to display it. For example an image file. So far the only way I've found to stop it is to close the shell. control + c, q, quit, haven't worked. I'm learning through denial and error so that's all I can think of to try.

So two questions: what is it called when this happens? And how can I avoid/stop it?

Thanks!

EDIT: Here are some screen shots

Before entering command

Lost control of shell

Continues until exiting shell..

Also makes the 'beep' sound continually (probably not the right terminology there)

So far I've tried:

Control + C
Control + Z
quit
exit
clear 
reset

Nothing seems to work since I can't enter commands

Solution:

Use 'less' instead of 'cat', since cat is the wrong tool for the job.

🌐
Linux 101
linux101.hashnode.dev › getting-out-of-the-cat-command-in-linux
Getting Out of the cat Command in Linux
March 28, 2024 - Ctrl+C and Ctrl+D can be used to exit many programs gracefully, sending the proper signals to allow them to shut down cleanly. And killall can act as a forceful hammer when needed as well.
🌐
CompuHoy
compuhoy.com › home › otros
How do you exit cat command in Unix? - CompuHoy.com
November 1, 2021 - Every Linux or Unix command executed by the shell script or user has an exit status. Exit status is an integer number. 0 exit status means the command was successful without any errors. A non-zero (1-255 values) exit status means command was a failure. Concatenate files and print on the standard output · To create a new file, use the cat command followed by the redirection operator ( > ) and the name of the file you want to create.
🌐
Linux Genie
linuxgenie.net › home › how to exit from the cat command
How to Exit from the Cat Command - Linux Genie
November 28, 2022 - To do that, you simply need to press the “Ctrl + D” key combination and you will instantly exit from the Cat command as shown in the following image: There are different terminal pager commands available in Linux such as “less”, “more”, ...
🌐
DevelopnSolve
developnsolve.com › getting-out-of-the-cat-command-in-linux
Getting Out of the cat Command in Linux - Develop and Solve
December 17, 2023 - Ctrl+C and Ctrl+D can be used to exit many programs gracefully, sending the proper signals to allow them to shut down cleanly. And killall can act as a forceful hammer when needed as well.
🌐
Code2care
code2care.org › home › q › how to stop or quit cat command?
How to stop or quit cat command? | Code2care
January 26, 2026 - If you are using more or less option along with cat command, lets see how to come out of the command back to prompt.
🌐
Ask Ubuntu
askubuntu.com › questions › 1228372 › how-to-quit-cat-in-grub-terminal-pre-boot
command line - How to quit `cat` in grub terminal pre-boot - Ask Ubuntu
In grub terminal (prior to system booting, in this situation), I have entered cat . Screenfuls of characters are now being output. E...
🌐
The Cat Bandit
blog.catbandit.com › how-to-exit-a-cat-file-a-step-by-step-guide
How to Exit a Cat File: A Step-by-Step Guide – The Cat Bandit Blog
In this guide, we’ll walk you through the step-by-step instructions for exiting a cat file using different methods. If you’re using the cat command in your terminal window, you can exit it easily using keyboard shortcuts. To do this, simply press Ctrl + C.