ac

system managementlinux
The ac command is one of the most frequently used commands in Linux/Unix-like operating systems. ac The ac command prints statistics about users' connect time on a Unix system. It reads the /var/log/wtmp file (or the file specified with the -f option) and reports the total connect time for all users or individual users.

Quick Reference

Command Name:

ac

Category:

system management

Platform:

linux

Basic Usage:

ac [options] [arguments]

Common Use Cases

    Syntax

    ac [options] [users...]

    Options

    Option Description
    -d, --daily-totals Print totals for each day instead of just one big total
    -p, --individual-totals Print time totals for each user
    -f, --file Read from specified file instead of /var/log/wtmp
    --complain Print complaints about bad records in input data
    --reboots Print reboot records
    --supplants Print login session suppression records
    --timewarps Print time warp records
    --compatibility Print in more traditional format
    -a, --all Print all records from database
    -t, --today Report connect time only for today
    -y, --yesterday Report connect time only for yesterday
    --print-year Print year on output
    --print-zeros Print entries with zero time
    -w, --print-wtmp-file Print the wtmp file that's being read
    --debug Print verbose internal information
    -h, --hours-only Print hours instead of hours and minutes
    --seconds Print seconds instead of hours and minutes
    --minutes Print minutes instead of hours and minutes
    --time-format=format Set format for printing times (hours, minutes, seconds, exact, iso, posix)
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the ac command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Print total connect time for all users
    ac
    # Show connect time for specific users ac john alice bob
    # Display statistics by day ac -d
    # Print hourly totals ac -p

    Advanced Examples:

    # Display individual totals for each day and the overall total
    ac -dp
    # Read from a specific wtmp file ac -f /var/log/wtmp.1
    # Show connect time in hours instead of the default hours and minutes ac -h # Display time in minutes ac --minutes # Display time for today only ac -t

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Understanding ac Output:

    The ac command displays connect time statistics in hours and minutes by default. The connect time is calculated based on login/logout records in the wtmp file.

    The wtmp File:

    The wtmp file records all logins and logouts on the system. On most Linux distributions, it's located at /var/log/wtmp. Older records may be rotated to files like /var/log/wtmp.1, /var/log/wtmp.2, etc.

    Output Formats:

    By default, ac reports total hours in the format "hours:minutes". You can modify this with the --hours-only, --minutes, or --seconds options.

    User Specification:

    If you specify usernames as arguments, ac will report connect time only for those users. Without arguments, it reports total connect time for all users.

    Combining Options:

    The -d (daily) and -p (per-user) options can be combined as -dp to show both daily totals and per-user breakdowns.

    Important Notes:

    • The ac command requires read access to the wtmp file, which usually requires root privileges
    • Statistics are only as accurate as the wtmp records; corrupted records may lead to inaccurate totals
    • If a user hasn't logged out properly (e.g., system crash), the connect time may be inaccurate
    • Time is measured from login to logout, not actual keyboard activity
    • The ac command is part of the GNU accounting utilities package

    Related Files:

    • /var/log/wtmp - Login/logout record file
    • /var/log/utmp - Current login information
    • /var/log/btmp - Failed login attempts

    Related Commands

    These commands are frequently used alongside ac or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ac command works in different scenarios.

    $ ac
    View All Commands