how can I find out all the commands entered by the user?
I need to know all my entered commands
OC: centOS
1 Answers
On all unix-based OS's this is typically achieved by using the history
command. If you want to search for a specific command in your history, you can use history | grep "cp"
. This command takes the output from the history command and pipes it (that's the | character) into grep which checks every line for the string cp
. To limit the amount of results the history command provides, add the desired number as the first argument to history: history 15
.
If you want to get the history of a different user that your current one, you have to switch to that user first: su myusername
.
Keep in mind that if you open multiple sessions as one user, only the first terminal you open will actually save the history if you use bash
.
If you need a combined history of all sessions of one user, I would recommend you to use a different shell, fish for example.

- 76
-
-
If you haven't closed the terminal you want to get the history from, you can try getting the previous commands by pressing the up key on your keyboard to show your previously typed commands. Otherwise, if the command doesn't show up in
history
it wasn't saved. – Morpheus0x Nov 15 '22 at 13:33
history
command will work the just as well. – Jos Nov 15 '22 at 12:19