
ac: Print accounting statistics
Introduction
ac is a small utility from the acct package that reports how long users have been connected to the system. It relies on process accounting data being collected, so if you don’t see any output, ensure the accounting system is enabled and the accounting files are being updated.
Basic usage (current user)
- Print how long the current user has been connected in hours:
ac
Notes:
- This shows the total session time for the current user since accounting started.
- If you don’t see meaningful output, the accounting data may not be enabled on your system.
Per-user totals
- Print how long users have been connected in hours (aggregate):
ac {{[-p|--individual-totals]}}
- Print how long a particular user has been connected in hours:
ac {{[-p|--individual-totals]}} {{username}}
What the flags mean:
- -p or —individual-totals switches the output to per-user totals instead of a single aggregate total.
Daily totals for a user (with per-user totals)
- Print how long a particular user has been connected in hours per day (with total):
ac {{[-d|--daily-totals]}} {{[-p|--individual-totals]}} {{username}}
- -d or —daily-totals breaks the totals down by day, showing daily totals in addition to the overall total when combined with -p/—individual-totals.
Additional details
- Also display additional details:
ac --compatibility
This option emits output that’s more verbose or compatible with older/specialized accounting formats.
Common pitfalls
- Accounting must be enabled: If ac prints nothing or shows zeros, the acct system may not be enabled or running. Check your distro’s service for accounting (often named acct or linux-pacct) and ensure the accounting file is being updated (pacct or pacct.0+ files).
- Data availability: If there’s no login history or recent activity, there may be no data to report. Try creating a login session and verifying data collection.
- Permissions: In some setups, reading accounting data may require elevated privileges. If you see permission errors, run with sudo or as root, or adjust permissions as appropriate for your environment.
Practical example: quick demo
- See total hours for all users, then drill down into a specific user:
ac
ac -p alice
Or see daily totals for a specific user:
ac -d -p alice
When to use ac
- Auditing: Quick checks of how long users have been connected for a shift or audit.
- Troubleshooting: Validate that login durations are being recorded if you suspect accounting is misconfigured.
TL;DR
- ac reports login durations using accounting data. If you don’t get data, enable accounting and ensure the pacct files are being updated. Use -p for per-user totals and -d for daily totals. Use —compatibility for older format output.