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?
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”.
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.
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 .
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 .
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 CONTROL
Enter will start searching, n will find the next match which is the right section.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With