Prevent accidental history editing in bash Prevent accidental history editing in bash shell shell

Prevent accidental history editing in bash


Each line maintains its own undo list which you can access with C-x C-u or C-_ to undo the most recent change, or M-r to revert all changes since it was last saved.


Is it possible to prevent bash from editing the commands that have already been run?

It is possible to to prevent this "feature". I found the solution via this answer over on unix.stackexchange.

To summarize, you need to enable the revert-all-at-newline readline setting which is off by default. If the setting is on then bash will revert any changes you made to your history when you execute the next command.

To enable this setting in your shell, you should add the following to your ~/.inputrc file and then restart your shell:

$include /etc/inputrcset revert-all-at-newline on

The first line is needed because I guess that if you supply your own .inputrc file the default /etc/inputrc file is not included which is probably not what you want.