Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I abort the current running bash command?

Tags:

linux

bash

Is it possible to manually abort the currently running bash command? So, for example, I'm using 'find' but it's taking ages... how do I manually stop it?

like image 610
Owen Avatar asked Nov 15 '10 11:11

Owen


People also ask

How do I abort a bash command?

There are many methods to quit the bash script, i.e., quit while writing a bash script, while execution, or at run time. One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.

How do I stop the current command?

Hold the Ctrl button and press the C key at the same time. It sends the SIGKILL signal to the running program to force quit the command. Do you see the ^C? The caret (^) means Ctrl.

How do you exit the current shell?

If your shell prompt is >>> you are in python . To exit from python type exit() or CTRL-D . If your shell prompt is ... you have an unclosed environment inside python . To interrupt the environment type CTRL-C .

How do I stop a program from running in bash?

To interrupt it, you can try pressing ctrl c to send a SIGINT. If it doesn't stop it, you may try to kill it using kill -9 <pid> , which sends a SIGKILL. The latter can't be ignored/intercepted by the process itself (the one being killed). To move the active process to background, you can press ctrl z .


2 Answers

Some things won't respond to Ctrl+C; in that case, you can also do Ctrl+Z which stops the process and then kill %1 - or even fg to go back to it. Read the section in man bash entitled "JOB CONTROL" for more information. It's very helpful. (If you're not familiar with man or the man pager, you can search using /. man bash then inside it /JOB CONTROLEnter will start searching, n will find the next match which is the right section.)

like image 198
Chris Morgan Avatar answered Sep 19 '22 14:09

Chris Morgan


Ok, so this is the order:

1st try: Ctrl+c

2nd try: Ctrl+z

3rd: login to another console, find the process of the command within your first console that is not responding to both previously mentioned abort/sleep keystrokes with: ps aux

Then kill the process with: kill -9 <PROCESSID>

Of course there may be smarter parameters to the ps command or the possibility to grep , but this would complicate the explanation.

like image 22
Nicolas Avatar answered Sep 20 '22 14:09

Nicolas