34

In a moment of brilliance, I executed the command source ~/.bash_history. Fortunately, most of the commands are using vim to edit some file, but there are some scary commands in my history - moving and removing files with relative paths.

Fortunately right now it's stuck in a vim session, however if I suspend or quit it, it's on to the next one. The history file is 1000 lines long.

How can I cancel this command, short of rebooting the machine?

migrated from stackoverflow.com Jun 19 '13 at 14:13

This question came from our site for professional and enthusiast programmers.

  • 23
    This is madness! :) – rectummelancolique Jun 19 '13 at 14:10
  • 7
    madness ? This is sparta! -- wait, sorry. – Sirex Jun 22 '13 at 5:58
  • 2
    I am not alone :) – Alupotha Jun 3 '18 at 14:06
28

If it's a local machine, start a new terminal and kill the shell in question.

If it's a remote machine, ssh in and kill the shell in question.

15

You can hit Ctrl+Z or start a subshell using :!bash, and then kill the shell. Specific steps:

Ctrl+Z
kill -9 $$

:suspend (or acceptable abbreviations thereof) may function equivalently to Ctrl+Z.

  • 6
    But if you :!bash, then $$ will refer to the subshell you just created. You’d need to use ps to find out the PID. ... P.S. I guess this is, to an extent, a question of style, but if there’s no need to do bash-fancy stuff, I would use just plain :!sh. Also, for that matter, try :sh. – Scott Jun 22 '13 at 2:53
  • 1
    Downvoting because, as the comment points out, as written this might give someone just enough false confidence to exit vim and hose their machine. – Parthian Shot Mar 25 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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