This question may sound weird. But here is what happened and I'd like to find out the ways to avoid this happening again.

I accidentally pasted contents of a text file into SSH CLI on Ubuntu 16.04. The machine was used for my production setup. I actually copied contents of a log file and intended to paste it in a nano editor opened in some other SSH window, but mistakenly pasted it on command line interface. The shell attempted to process every line as a command and created some junk files in local directory.

This fortunately didn't cause much damage however I want to know is there any way to avoid the accidental paste on ubuntu command line? Or can I disable the command line for multiline inputs?

I use PAC ssh client to connect to my remote systems.


Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:

set enable-bracketed-paste

You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.

Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.

Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'\e[?2004h'. This may be a bit esoteric.

|improve this answer|||||

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.