Quick Tips

Disabling Shell History File from BusyBox

Just a quick tip this time. I couldn’t find a solution to this by googling, and ChatGPT hallucinated a mostly wrong answer, so here are my tricks for disabling shell history files (~/.ash_history and ~/.hush_history) from BusyBox shells ash and hush.

This has happened more than once.

Build Time Disable

To completely disable writing the command history to a file, add the following snippet to your BusyBox configuration:

 # CONFIG_FEATURE_EDITING_SAVEHISTORY is not set

Editing is the feature that allows modifying the command line contents. For example, if you write a long command, and want to fix a typo in the beginning, you can edit the beginning without having to retype the whole command. For one reason or another, saving the history is part of this feature. You can also set CONFIG_FEATURE_EDITING_HISTORY=0 to store zero commands in the history, but this also applies to the shell session memory history. This means you cannot use the up arrow key to search for previous commands.

The good part of this approach is that you’ll save some space with smaller busybox binary. Also, you cannot incorrectly configure it and enable the history.

Run Time Disable

To “disable” writing the command history to a file, you can set HISTFILE to /dev/null either in /etc/profile (for all users) or ~/.profile (for one user):

HISTFILE=/dev/null

Unsetting HISTFILE does not work, because it seems that ash/hush then use the default file under ~ if HISTFILE is not set in the shell profile. From what I understood, setting HISTFILESIZE to zero should prevent anything from getting written to the history file, but BusyBox seems to force the length of the history to at least one if the maximum history is more than zero (see size_from_HISTFILESIZE function). Setting HISTSIZE sets the number of commands stored in memory during the shell session, so it doesn’t matter for the history file. This StackOverflow answer goes through the two size variables in depth.

The good part of this approach is that it’s configurable. Also, if you need to enable the history later on, it is possible.

That’s all. Hopefully, this helps with BusyBox shells, they seem to operate a bit differently compared to for example bash.