LinuxCommandLibrary

hledger-accounts

Show account names from hledger journal file

TLDR

Show all accounts used or declared in the default journal file

$ hledger [[acc|accounts]]
copy

Show accounts used by transactions
$ hledger [[acc|accounts]] [[-u|--used]]
copy

Show accounts declared with account directives
$ hledger [[acc|accounts]] [[-d|--declared]]
copy

Add new account directives, for accounts used but not declared, to the journal
$ hledger [[acc|accounts]] --undeclared --directives >> [2024-accounts.journal]
copy

Show accounts with asset in their name, and their declared/inferred types
$ hledger [[acc|accounts]] asset --types
copy

Show accounts of the Asset type
$ hledger [[acc|accounts]] type:A
copy

Show the first two levels of the accounts hierarchy
$ hledger [[acc|accounts]] [[-t|--tree]] [[-2|--depth 2]]
copy

SYNOPSIS

hledger accounts [OPTIONS] [PATTERN]

PARAMETERS

--tree
    Show a collapsible account name tree

--flat
    Show a flat list of accounts (default with pattern)

--drop N
    Show only the last N parts of each account name

--no-total
    Hide the summary total line

--only
    Show only accounts with postings (default)

-f --file FILE
    Use additional journal files

--register
    Show individual postings instead of accounts

-h --help
    Show command help

DESCRIPTION

The hledger accounts command displays all account names appearing in the journal file(s) loaded by hledger, along with the number of postings to each account and the files where they appear. It provides a quick overview of the account structure in your plain text accounting data.

By default, accounts are shown in a hierarchical tree format based on their names (eg Equity:Opening Balances, Expenses:Food:Groceries), sorted alphabetically. Each account line includes: the full account name, posting count, and file names (truncated if long).

A PATTERN argument (a case-insensitive regex) can filter accounts, showing only matching ones. This is useful for exploring subsets, like all "Assets" accounts.

Options allow customising the view: --flat for a simple list without hierarchy; --tree for an interactive collapsible tree (in terminal); --drop N to shorten account names by dropping the first N parts; and more. It respects hledger's standard options like --file for custom journals.

This command is invaluable for data validation, refactoring account names, or generating account lists for reports. Output is precise and grep-friendly, aiding scripting.

CAVEATS

Output tree requires a capable terminal; patterns are regex and case-insensitive. Does not show unused accounts by default. Large journals may be slow without filtering.

EXAMPLE USAGE

hledger accounts Assets — lists all asset accounts.
hledger accounts --flat --drop 1 — flat list of account leaf names.

OUTPUT FORMAT

Each line: ACCTNAME (N) file.journal...
Summary shows total accounts and postings.

HISTORY

Part of hledger since v0.1 (2007), developed by Simon Michael. Evolved with tree/flat views in v0.20+; aligns with Haskell reimplementation for performance.

SEE ALSO

Copied to clipboard