A Linux account's command trail is spread across saved shell history, sudo records, and running processes. Checking these sources together helps identify commands associated with one user while accounting for gaps in each source.

Shell history holds only what a person typed at an interactive prompt. It can be turned off, edited or cleared, and a session that is still open may not have saved its latest commands, so even reading every user's history does not give a complete record of what ran on the system.

Privileged commands leave a second record in the sudo logs, though sudo records only the command it starts, not what is typed later inside a root shell. Missing entries do not prove a command was never run, so treat each source as a clue and confirm anything important before acting on the account.

Shell history and logs can contain passwords, tokens, or other private data. Access another account's records only with authorization, and keep the output private.

Steps to check commands run by a user in Linux:

  1. Read the saved Bash history file for the account.
    $ sudo cat /home/alice/.bash_history
    #1793918641
    id
    #1793918643
    sudo whoami
    #1793918646
    sudo systemctl restart rsyslog
    #1793918650
    exit

    The examples use alice as the account being checked. Bash usually saves a session's commands when the shell exits, so an open session may be missing from the file. If the file is not there, getent passwd alice prints the account's home directory and login shell. Zsh commonly uses ~/.zsh_history and fish uses ~/.local/share/fish/fish_history.
    Related: Manage your own Bash history
    Related: Manage Zsh history

  2. Convert a timestamp line to a readable date if the file has any.
    $ date -d @1793918643
    Thu Nov  5 22:44:03 UTC 2026

    Lines starting with # hold the time in seconds since 1970, and Bash writes them only when HISTTIMEFORMAT is set. Without them the file shows the order of commands but no dates, and setting it now cannot recover them.

  3. List the sudo commands run by the user.
    $ sudo journalctl -t sudo | grep ' alice : '
    Nov 05 22:44:03 server01 sudo[156]:    alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/whoami
    Nov 05 22:44:06 server01 sudo[171]:    alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/systemctl restart rsyslog

    The COMMAND= field shows what ran, and the spaces around alice : limit the match to that account name. No lines means no retained records, not proof that the user never used sudo. On a host that writes text logs, sudo zgrep ' alice : ' /var/log/auth.log* also searches the rotated files; Red Hat-family systems use /var/log/secure*.
    Related: How to check authentication logs in Linux

  4. List the commands running under the account right now.
    $ ps -fu alice
    UID          PID    PPID  C STIME TTY          TIME CMD
    alice        203     201  0 22:44 ?        00:00:00 sleep 300

    This shows only what is running at this moment. Finished commands are gone from this list, and a command started with sudo runs as root, so it does not appear here.
    Related: How to view processes by user in Linux

Share this guide