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] [ACCOUNT_QUERY...]

PARAMETERS

-f FILE, --file=FILE
    Specifies the journal file to read. If not provided, hledger looks for a default file (e.g., ~/.hledger.journal).

-b, --balance
    Shows the current balance of each account alongside its name.

-B, --cost
    Shows balances valued at cost basis.

-C, --market
    Shows balances valued at market price.

-E, --empty
    Includes accounts with zero balance or no transactions. By default, these are hidden unless queried directly.

-T, --tree
    Displays accounts in a hierarchical tree structure. This is the default display mode.

-S, --flat
    Displays accounts in a flat (non-hierarchical) list.

-n, --count
    Shows the total number of transactions affecting each account.

-O, --unmarked
    Shows only accounts that are not marked (e.g., with (closed) or (virtual)) in the journal file.

-o FORMAT, --output-format=FORMAT
    Specifies the output format, such as csv for comma-separated values, json, or text.

-s FIELD, --sort=FIELD
    Sorts the accounts by a specified field (e.g., name, balance).

--depth=N
    Limits the displayed account hierarchy to a specified depth N.

[ACCOUNT_QUERY...]
    One or more regular expressions or account names to filter the displayed accounts. Only accounts matching the query will be shown.

DESCRIPTION

The hledger accounts command is a fundamental subcommand of the hledger plain text accounting system. Its primary function is to parse one or more journal files and present a comprehensive, hierarchical list of all accounts defined within them. This command is invaluable for understanding the structure of your financial records, auditing account names for consistency, or quickly locating specific accounts.

By default, hledger accounts displays accounts in a tree-like structure, reflecting their parent-child relationships (e.g., 'Assets:Bank:Checking'). It can also be configured to show flat lists, include account balances, transaction counts, or even market values, depending on the specified options. It supports filtering accounts using a query, allowing users to focus on specific branches or types of accounts. This makes it a versatile tool for both daily accounting oversight and deeper analysis of your financial setup, ensuring that all defined accounts are visible and correctly spelled.

CAVEATS

The hledger accounts command relies entirely on the correctness and completeness of your hledger journal file(s). Any accounts not explicitly defined or implicitly used in transactions will not appear. Output can be extensive for very large journals without specific filtering via ACCOUNT_QUERY arguments. Ensure hledger is installed and accessible in your PATH.

JOURNAL FILE DEPENDENCY

The command operates by parsing hledger journal files, typically named .journal or .dat. These files contain all your account definitions, transactions, and other financial records. The structure of your accounts (e.g., Assets:Cash, Expenses:Groceries) is entirely derived from how you define them in these journal files. Without a valid journal, hledger accounts has no data to display.

ACCOUNT QUERYING

The optional ACCOUNT_QUERY arguments allow for powerful filtering of the accounts list. You can specify a full account name (e.g., Assets:Bank:Checking) or use regular expressions (e.g., Expenses.*) to display only a subset of your accounts. This is particularly useful for large journals or when you only need to inspect a specific branch of your account hierarchy.

HISTORY

hledger, the plain text accounting system, was created by Simon Michael and first released in 2007 as a Haskell-based re-implementation of the popular ledger command-line accounting tool. The accounts subcommand has been a core and indispensable part of hledger from its early days, serving as one of the primary ways users can inspect and understand the structure of their financial data. Its design benefits from the robustness and expressiveness of Haskell, making it a reliable and efficient tool for plain text accounting enthusiasts.

SEE ALSO

hledger(1), hledger-balance(1), hledger-print(1), hledger-register(1), ledger(1)

Copied to clipboard