How can I check the user command history in Unix?
55,687
Solution 1
You get a list of currently logged in users in /var/run/utmp
(see man 5 utmp
). The history is stored in ~/.history or for bash user in ~/.bash_history. Other shells may use other history files, so it's not that easy to get really all information.
Furthermore, if a user is logged in multiple times, the .bash_history file is not always reliable.
To read the utmp
file there is a "frontend" called who
, so you could also write a shell-script to iterate over the currently logged in users.
Solution 2
echo $HISTFILE
Then view that file.
Related videos on Youtube
Author by
Gaff
Updated on September 17, 2022Comments
-
Gaff over 1 year
I know the 'history' command give me a list of the commands I have typed into the Unix terminal.
How do I see the command history for all of the users currently logged onto the system?
-
Admin over 13 yearsNot programming related. I suggest you ask on superuser.com.
-
Admin over 13 yearsThere is no standard-tool to get the information, so I think it is programming (at least in the sense of 'scripting') - related.
-
-
Dennis Williamson over 13 yearsThe current history is held in memory. The history file only shows what was written using
history -a
or similar or when a user exits the shell. -
DevSolar almost 12 yearsThis works only if you have previously sourced that user's environment (as he might have set
HISTFILE
to something else).