Right, this is a slightly annoying feature because something this happens, and other times it doesn't, very odd.

I paste a command into the terminal with a view to tweaking its arguments, and sometimes it executes the second I paste it. Sometimes it doesn't.

This ranges from embarrassing ( posting nonsensical comments on an IRC ) to dangerous.

How can I shut this feature off for good? I never, never, never want the terminal to auto execute when I paste to it.


There's no auto execution. You probably are also copying a line break (or more) after the command.

If you paste a command with a break, the shell (command line) thinks that you hit the break (Enter, Return) button by yourself.

This answer only explains why OP is getting the undesired behaviour. However, in another answer, there is a real solution to the OP’s problem.


One real solution is to open editing mode with ctrl-x ctrl-e and then safely paste your clipboard into your editor of choice (commonly emacs or vim). After you are done editing the command, save and exit and it will run in the command line. This is a good habit for long or complex commands, especially when pasting commit hashes into git commands, and can help you avoid some scary results in the long run.

The editor can be changed by setting the VISUAL and EDITOR variables (these have different meanings, see here).

  • wow, there is always something to learn after decades of using linux :) thanks, this is the only answer that actually solves the problem – törzsmókus Jun 29 '18 at 7:35
  • Sounds like it might work for a real linux terminal, but unfortunately this isn't helpful for PuTTY users. Any other alternatives? – Codesmith Oct 27 '18 at 18:00
  • 1
    @Codesmith I believe that Pawel Chioch's comment on the accepted answer may be helpful to you: serverfault.com/questions/731022/… – borrascador Oct 28 '18 at 0:56
  • 1
    Good point @borrascador! Not sure how I missed that. Thanks! :) – Codesmith Oct 29 '18 at 0:23

Prior to pasting type a # then paste your line. It will not execute and you can remove the # and hit enter when the modifications have been completed.

  • You could also use true AKA :, which is basically a no-op command. – wjandrea Dec 22 '17 at 21:56
  • 1
    @WJAndrea I would say this is less advisable since it will clobber the exit status ($?)... true isn't really a nop, it returns exit status 0. A comment, on the other hand, is entirely ignored and therefore won't alter $?. – brhfl Jan 25 '18 at 19:52
  • 5
    this will only stop the first line from executing. if OP pastes a text with at least two line breaks, they are screwed again. – törzsmókus Jun 29 '18 at 7:29

I use this alias to paste and have my command NOT-executed

alias nonewlinepaste='history -s `xsel -b`; sleep 1; xdotool key Up 1>/dev/null'  # xsel ref. https://unix.stackexchange.com/a/96398/17671  # xdotool ref. https://unix.stackexchange.com/questions/267704/command-to-simulate-keyboard-input#comment1038650_267705

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.