I sometimes accidentally press Ctrl-D while using a terminal, exiting the terminal or closing screen/tmux.

Can I avoid this by having a confirmation before exit like this?

Are you sure you want to quit? [Y/n]


Press Ctrl-D again to quit

The answer in general is "no", you are providing an end of file (EOF) indication to the program running in the terminal/screen/tmux, but bash for example allows you to say


and then it takes 4 control-D characters in a row to exit the shell.

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