linuxbashubuntuinput-history

Print the history for the last 10 Commands on the session on each log in to the shell


I'm trying to print out the last 10 commands on the last session on each login, in the bash.bashrc. I wrote this:

echo "$(history 10)"

But it didn't print anything.


Solution

  • Bash history is only loaded from file after .bashrc has completed.

    You can force the loading of history and then output what you want by adding the following to your .bashrc file:

    history -r
    history 10