When I am logged into the ESXi Shell, I often forget that history command is not implemented in ESXi which can be helpful when recalling the list of operations that had been executed in the past. I especially rely on the history command when I am tinkering around with things and once I am successful with the end result, I can easily go back and see the exact steps I took. Recently, I tried running history command only to be let down again as I forgot it was not implemented 🙁
I was thinking there had to be a way on ESXi and then it hit me! Starting with ESXi 5.1, all operations executed in ESXi Shell and Console were automatically logged to /var/log/shell.log. The information I was looking was there but instead of having to manually view the contents of the log, I could simply create an "alias" to a history command which could display the last N-number of entries using the tail command.
Here is an example alias to "history" command to view the last 50 lines in /var/log/shell.log:
alias history="tail -50 /var/log/shell.log"
To make the alias permanent and persist across reboots, we just need to add the entry to /etc/profile.local
Now, I can run the history command on ESXi and get exactly what I want.
Note: Entries in /var/log/shell.log contain more operations executed by all users. You can further refine the aliased command to search only for the current user, such as the root account.