Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I expect to get some flak for this, but I can't find the answer anywhere. It seems like it should be so obvious. Sometimes, when I type a bad command in a bash terminal, the cursor just jumps down to the next line without any error or anything. I can't tell what I did wrong. It's like I'm stuck in the program. Reenactment:

$ tidy

Me: "Oops! That's not what I meant to type..."

:q

Me: "That didn't work..."

:exit
:quit
exit
quit
/exit
/quit
-exit
-quit
-wtf???

I know I screwed up but how do I get back to the prompt without closing the terminal?

share|improve this question
    
Related: What causes various signals to be sent? – Gilles Aug 16 '12 at 23:23
up vote 21 down vote accepted

You can always try the obvious things like ^C, ^D (eof), Escape etc., but if all fails I usually end up suspending the command with ^Z (Control-Z) which puts me back into the shell.

I then do a ps command and note the PID (process id) of the command and then issue a kill thePID (kill -9 thePID if the former didn't work) command to terminate the application.

Note that this is not a tidy (no pun intended) way to terminate the application/command and you run the risk of perhaps no saving some data etc.

An example (I'd have used tidy but I don't have it installed):

$ gnuplot

    G N U P L O T
    Version 4.2 patchlevel 6 
     ....
    Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>

Terminal type set to 'wxt'
gnuplot> 
gnuplot>               #####  typed ^Z here
[1]+  Stopped                 gnuplot
$ ps
  PID TTY          TIME CMD
 1681 pts/1    00:00:00 tcsh
 1690 pts/1    00:00:00 bash
 1708 pts/1    00:00:00 gnuplot
 1709 pts/1    00:00:00 ps


$ kill 1708            ###### didn't kill the command as ps shows

$ ps
  PID TTY          TIME CMD
 1681 pts/1    00:00:00 tcsh
 1690 pts/1    00:00:00 bash
 1708 pts/1    00:00:00 gnuplot
 1710 pts/1    00:00:00 ps
$ kill -9 1708           ### -9 did the trick
$ 
[1]+  Killed                  gnuplot

$ ps
  PID TTY          TIME CMD
 1681 pts/1    00:00:00 tcsh
 1690 pts/1    00:00:00 bash
 1711 pts/1    00:00:00 ps
share|improve this answer
1  
That's it!! ^Z to the rescue. Thank you so much. – Dave Kennedy Aug 16 '12 at 17:38
3  
^\ (ctrl-backslash, SIGQUIT) works in some stubborn utilities that don't respond to ^C. – mrb Aug 16 '12 at 19:11
2  
Shh! Don't tell people about the ^\ or they'll start SIG_IGN'ing that too, then what will we do? – Alan Curry Aug 16 '12 at 19:55
1  
@godlygeek Can you tell me what %% means in Linux or what kind of thing it is? I searched a lot. – Noumenon Jan 27 at 17:17
1  
@Noumenon, have a look at LESS='+/^JOB CONTROL' man bash. %% refers to the "current job". – Wildcard Mar 15 at 1:49

Try pressing Ctrl-D or Ctrl-C. If it fails, kill the process .

Trying with the tidy command you mentioned, Ctrl-D works.

share|improve this answer

Another solution (not mentioned already) is to send the SIGQUIT signal using ctrl+\

It is stronger than a ctrl+c

share|improve this answer

CTRL+D == exit shell command

and

CTRL+C == terminate the current process, Of course may be the given software handle it and CTRL+D doens't work

Of course , They produce a kernel signal if you want to know more, read :

man 7 signal
share|improve this answer
2  
Ctrl+D is end-of-file, not directly exit. – Gilles Aug 16 '12 at 23:22

protected by Community May 23 at 0:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.