"History" is a very useful command for finding out which commands were most recently executed on a Server. By default, the command will display the last 500 commands executed, taking this data from the .bash_history file in the home directory of the user themself (or from /root/.bash_history in the case of the root user).
To use it, we will need to access the server via SSH:
Additional information
You can find more information about accessing your server via SSH in the article:
Once connected, if you run the command:
# history
It should display a result similar to the following:
496 ls -la
497 ls
498 history
499 ls
500 cd dominios
501 cd ..
Additional ways to use the command
If the output is very long and you want to review all of it page by page, simply use it with the command "less".
Once the list of results is displayed, you can use the "space" key to move through the pages:
# history | less
To check only the last ten lines:
# history | tail
To check the last 25 lines, you can specify this as follows:
# history 25
To search for a specific word, path, or command in the history, you can use the history command together with the grep command:
# history | grep mv
It is important to know that the grep command supports regular expressions to help with searching.