Shell – How to remove “exit” command from Linux shell

exitshell

I am working on Linux Ubuntu 16.04.
In this challenge I want to remove some commands from the Linux shell.

Specifically, I want to remove the exit command.
I want that if a user will try to exit the shell with this command, it won't be possible or maybe even send some message instead.

Any idea how can I do it ?
I searched for a file named exit:
find / -name exit

But it found only directories:

/usr/src/linux-headers-4.13.0-41-generic/include/config/have/exit
/usr/src/linux-headers-4.13.0-41-generic/include/config/have/irq/exit
/usr/src/linux-headers-4.13.0-43-generic/include/config/have/exit
/usr/src/linux-headers-4.13.0-43-generic/include/config/have/irq/exit
/usr/src/linux-headers-4.13.0-36-generic/include/config/have/exit
/usr/src/linux-headers-4.13.0-36-generic/include/config/have/irq/exit
/usr/src/linux-headers-4.15.0-43-generic/include/config/have/exit
/usr/src/linux-headers-4.15.0-43-generic/include/config/have/irq/exit

EDIT:
I read here about using trap like this trap "ENTER-COMMAND-HERE" EXIT and I tried trap "sh" EXIT but it still existing the shell.

Best Answer

There is no exit executable, that is one of the shell's (you don't say what shell, so I am assuming bash) builtin commands. As such, the only way to remove it completely is to edit the source code of the shell and recompile it (but look at @Kusalananda's answer for a better approach).

As an alternative, you could add something like this to /etc/bash.bashrc:

alias exit='echo "You can check-out any time you like, but you can never leave!"'

But this is trivially easy to circumvent by anyone who knows even a little bit about *nix.

Related Question