LinuxCommandLibrary

lastcomm

displays information about previously executed commands from process

TLDR

Show recent commands

$ lastcomm
copy
Show commands by user
$ lastcomm [username]
copy
Show specific command
$ lastcomm --command [vim]
copy
Show from specific file
$ lastcomm -f [/var/account/pacct]
copy
Show commands by terminal
$ lastcomm --tty [pts/0]
copy

SYNOPSIS

lastcomm [options] [user] [command] [terminal]

DESCRIPTION

lastcomm displays information about previously executed commands from process accounting data. It shows command name, flags, user, terminal, and execution time.
Process accounting must be enabled for lastcomm to have data. The accounting file is typically /var/account/pacct.

PARAMETERS

--command name

Filter by command name.
--user name
Filter by user.
--tty name
Filter by terminal.
-f file
Use specific accounting file.
--forwards
Show oldest first.
--strict-match
Exact match only.
--debug
Debug output.

OUTPUT FLAGS

$ S - Superuser (root) executed
F - Forked but didn't exec
D - Dumped core
X - Killed by signal
copy

ENABLING ACCOUNTING

$ # Enable accounting
sudo accton /var/account/pacct

# Disable accounting
sudo accton off
copy

CAVEATS

Requires process accounting enabled. Accounting adds system overhead. File grows continuously (rotate with sa). Not available on all systems.

HISTORY

lastcomm is part of the Unix process accounting system, dating back to early Unix. It provides historical tracking of executed commands, useful for auditing and troubleshooting.

SEE ALSO

sa(8), accton(8), last(1), ac(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community