Hledger Cheat Sheet

From WikiOD

Here is the cheatsheat of Hledger and basic guide on how to use Hledger

Reporting[edit | edit source]

hledger bal {query}
hledger reg {query}


Query[edit | edit source]

Queries are used on all commands (bal, reg, etc). (docs)

Assets           # An account (regex)
acct:Assets      # same
^Assets          # Starting with Assets (eg, not 'Expenses:Assets')

acctonly:A       # no subaccounts

amt:2000         # amount (in absolute value)
amt:<200         # amount comparison (in absolute value)
amt:<+200        # amount comparison
                 # also: <=, >, >=

desc:REGEX      # description
code:REGEX      # transaction code (check number?)

real:            # real posts
real:0           # virtual posts

depth:N          # --depth 2
not:...          # eg, not:status:!

Filter by status/type[edit | edit source]

real:1           # -R, --real, no virtuals
status:!         #     --pending
status:*         # -C, --cleared
status:          #     --uncleared

Periods[edit | edit source]

For dates and intervals (see above).

date:2015/01/01-    # -b, --begin
date:-2015/01/01    # -e, --end
-p, --period=...
  -p "2009/01/01"
  -p "2009/01/01 to 2009/12/31"
  -p "2009/01/01to2009/12/31"      # spaces optional
  -p "1/1 to 12/31"
  -p "to 2009"
  -p "weekly"                      # -W, --weekly
  -p "weekly 2009/01/01 to 2009/12/31"

Intervals[edit | edit source]

Used on all commands (bal, reg, etc). Displays in multi-column mode. In ledger-cli, only reg is supported. Can also specified via -p (period).

-D, --daily
-W, --weekly
-M, --monthly
-Q, --quarterly
-Y, --yearly

Smart dates[edit | edit source]

Used for --period, --begin and --end (-p -b -e).

-p 2015/01/01
-p 2015/01
-p 2015
-p january
-p jan
-p 05/25
-b today
-b yesterday
-e tomorrow
-p this week
-p last month
-p this year

Display formats[edit | edit source]

    --tree          # only in bal

    --depth 2       # collapse those under this depth
    --drop 1        # drop top-level accounts
-B, --cost          # convert to default currency
-E, --empty         # don't strip out $0 accounts
    --date2         # use date2 when available

Multi-column mode[edit | edit source]

When used with intervals (like --weekly):

-T, --row-total
-N, --no-total

Also: (only in bal)

    --cumulative    # show ending balance per period
-I, --historical    # like --cumulative but only for --begin
-A, --average

Accounts[edit | edit source]

hledger accounts [--tree]

Other commands[edit | edit source]

hledger balancesheet       # bs
hledger incomestatement    # is
hledger cashflow           # cf
hledger print
hledger activity
hledger stats

Examples[edit | edit source]

# Current balance
  hledger bal Assets
  hledger balancesheet

  hledger balancesheet Assets [--cleared --cost --empty -e tomorrow]
  # ...discard future stuff; convert foreign currencies

# Monthly changes in assets
  hledger bal Assets Liabilities --monthly --tree --historical [--cleared --cost --empty -e tomorrow]

# Weekly expenses
  hledger bal Expenses --weekly --average --tree -b 'last month' [--cleared --cost --empty -e tomorrow]

See also[edit | edit source]