The logic applies to many other objectives. And how to read .sh_history of each user from /home/ filesystem? What if there are thousand of them?
This is Hard. You will have to interpret each user's
~/.bashrc, and all the "Startup Files" for each and every shell to see what "the history file" really is.
For example, mine sets my history file to
~/.history/history.$$, and I currently have 1372
[[ -d ~/.history ]] || mkdir --mode=0700 ~/.history [[ -d ~/.history ]] && chmod 0700 ~/.history HISTFILE=~/.history/history.$$ # close any old history file by zeroing HISTFILESIZE HISTFILESIZE=0 # then set HISTFILESIZE to a large value HISTFILESIZE=4096 HISTSIZE=4096
Other users may do other things, may call their
.history files something else, use other shells, ...