LinuxCommandLibrary

ac

Report user connection time (login duration)

TLDR

Print how long the current user has been connected in hours

$ ac
copy

Print how long users have been connected in hours
$ ac -p
copy

Print how long a particular user has been connected in hours
$ ac -p [username]
copy

Print how long a particular user has been connected in hours per [d]ay (with total)
$ ac -dp [username]
copy

SYNOPSIS

ac [-p] [-d] [-t] [-W] [-w wtmp] [-P paper] [username...]

PARAMETERS

-p
    Print connect time for all users listed in wtmp

-d
    Display connect time totals for each day

-t
    Separate today's records from earlier ones with asterisks

-W
    Print connect time totals for each week

-w wtmp
    Read login records from specified wtmp file (default: /var/log/wtmp)

-P paper
    Set output paper size (default: a4)

username...
    Show totals only for specified users

DESCRIPTION

The ac command displays the total connect time for users on a system, calculated from login and logout records in the wtmp or utmp log files. Connect time represents the cumulative hours a user was logged in, derived by subtracting login timestamps from logout timestamps. If no logout record exists for a session, the time is calculated up to the current moment or the end of the log file.

It is primarily used for system accounting to track resource usage over time. By default, ac shows totals for current users or specified users from /var/log/wtmp. Output includes hours and possibly fractional minutes. The command supports filtering by user, daily/weekly breakdowns, and custom log files, making it useful for auditing login patterns, billing, or performance analysis.

Note that ac relies on accurate wtmp records maintained by login processes. Incomplete logs (e.g., due to crashes) may lead to inaccurate totals. It does not account for idle time or multiple sessions precisely unless specified.

CAVEATS

Requires read access to wtmp files; incomplete records cause undercounts. Does not handle reboots or idle sessions perfectly. Output may be large on busy systems.

DEFAULT FILES

Uses /var/log/wtmp for historical data and /var/run/utmp for current sessions.
Ensure log rotation preserves data.

EXAMPLE USAGE

ac -p (all users total)
ac -d user1 (daily totals for user1)

HISTORY

Originated in Version 7 Unix (1979). Standardized in SUSv2; remains in modern Linux via acct or util-linux packages with minor enhancements for output formatting.

SEE ALSO

last(1), lastb(1), w(1), who(1), utmp(5), wtmp(5)

Copied to clipboard