Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Aug 21 '10 at 4:06

This question came from our site for professional and enthusiast programmers.

    
Not programming related. I suggest you ask on superuser.com. –  Troubadour Aug 19 '10 at 9:47
    
There is no standard-tool to get the information, so I think it is programming (at least in the sense of 'scripting') - related. –  IanH Aug 19 '10 at 9:58

2 Answers 2

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.

share|improve this answer
2  
The 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. –  Dennis Williamson Aug 19 '10 at 15:31
2  
Note that the file names given in this answer are merely the defaults. Each user could have set his own location (see Joy's answer). If a user is using different shells, they could conceivably store their histories in different, non-default locations (e.g. ~/mybashhist, ~/histories/ksh or somesuch). Also, be aware that peeking user data like that might have legal implications. –  DevSolar Jul 25 '12 at 7:09
echo $HISTFILE

Then view that file.

share|improve this answer
1  
This works only if you have previously sourced that user's environment (as he might have set HISTFILE to something else). –  DevSolar Jul 25 '12 at 7:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.