2014-02-25 10:32:14 +00:00
|
|
|
---
|
|
|
|
title: Ledger CLI
|
2015-12-01 05:41:43 +00:00
|
|
|
category: Ledger
|
2020-07-04 13:33:09 +00:00
|
|
|
updated: 2020-05-23
|
2017-08-29 15:43:49 +00:00
|
|
|
weight: -5
|
2014-02-25 10:32:14 +00:00
|
|
|
---
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
### Basic usage
|
2014-07-30 05:53:29 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
$ ledger bal
|
|
|
|
$ ledger reg
|
|
|
|
```
|
2014-07-30 05:53:29 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
2017-08-28 20:27:00 +00:00
|
|
|
$ ledger reg grocery # show entries for 'grocery'
|
|
|
|
$ ledger bal assets # check if i'm broke
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
2014-07-30 05:53:29 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
-b 01/01 # --begin
|
|
|
|
-e 01/31 # --end
|
|
|
|
-S date # --sort
|
|
|
|
-S amount
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
### Examples
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
# any/all matches
|
|
|
|
ledger bal Rent Transportation # any
|
|
|
|
ledger bal Income and Job # all
|
|
|
|
ledger bal Expenses and not (Drinks or Food)
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# what did I spend on most? (--sorted)
|
|
|
|
ledger reg Expenses -S amount
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# how much did I have at this date? (--end)
|
|
|
|
ledger bal -e 01/15 ^Assets ^Liabilities
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# how much did I spend and earn this month?
|
|
|
|
ledger bal ^Expenses ^Income --invert
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# how much was spent over the course of 3 days? (totalled)
|
|
|
|
ledger reg -b 01/25 -e 01/27 --subtotal
|
|
|
|
ledger reg -b 01/25 -e 01/27 --subtotal grocery
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2014-07-30 05:53:29 +00:00
|
|
|
Format
|
|
|
|
------
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
### Basic format
|
|
|
|
|
|
|
|
```
|
|
|
|
2013/01/03 * Rent for January
|
|
|
|
Expenses:Rent $600.00
|
|
|
|
Assets:Savings
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
`*` = cleared, `!` = pending
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Secondary dates
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
|
|
|
2008/01/01=2008/01/14 Client invoice
|
|
|
|
```
|
|
|
|
|
|
|
|
It can mean anything you want, eg, for the estimated date you'll be paid.
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Balance assertions
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
|
|
|
2008/01/01 * KFC
|
|
|
|
Expenses:Food $20
|
|
|
|
Assets:Cash $-20 = $500
|
|
|
|
```
|
|
|
|
{: data-line="3"}
|
|
|
|
|
|
|
|
`Cash $X = $500` ensures Cash is at $500 after the transaction.
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Balance assignment
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
2008/01/01 * Cash balance
|
|
|
|
Assets:Cash = $500
|
|
|
|
Equity:Adjustments
|
|
|
|
|
|
|
|
2008/01/01 * KFC
|
|
|
|
Expenses:Food $20
|
|
|
|
Assets:Cash = $500
|
|
|
|
```
|
|
|
|
{: data-line="2,7"}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
`ACCOUNT = $500` figures out what's needed to make it $500.
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Payables
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
2008/04/25 * Rent
|
|
|
|
(Assets:Checking) -$200
|
|
|
|
Expenses:Rent
|
|
|
|
```
|
|
|
|
{: data-line="2"}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Commodities
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
; cost per item
|
|
|
|
2010/05/31 * Market
|
|
|
|
Assets:Fridge 35 apples @ $0.42
|
|
|
|
Assets:Cash
|
|
|
|
```
|
|
|
|
{: data-line="3"}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
; total cost
|
|
|
|
2010/05/31 * Market
|
|
|
|
Assets:Fridge 35 apples @@ $14.70
|
|
|
|
Assets:Cash
|
|
|
|
```
|
|
|
|
{: data-line="3"}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
; fixed lot prices
|
|
|
|
2010/05/31 * Gas
|
|
|
|
Expenses:Gasoline 11 GAL {=$2.299}
|
|
|
|
Assets:Cash
|
|
|
|
```
|
|
|
|
{: data-line="3"}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2014-06-07 14:32:02 +00:00
|
|
|
### Commodity definitions
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
|
|
|
commodity $
|
|
|
|
note American Dollars
|
|
|
|
format $1,000.00
|
|
|
|
nomarket
|
|
|
|
default
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Budgeting
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
|
|
|
~ Monthly
|
|
|
|
Expenses:Rent $500
|
|
|
|
Expenses:Food $100
|
|
|
|
Expenses $40 ; everything else
|
|
|
|
Assets
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
~ Yearly
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
ledger bal --budget Expenses
|
|
|
|
ledger bal --unbudgeted Expenses
|
|
|
|
```
|
|
|
|
{: .-setup}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Comments
|
|
|
|
|
2016-02-24 16:49:28 +00:00
|
|
|
; line comment
|
|
|
|
# also line comment
|
|
|
|
% also line comment
|
|
|
|
| also line comment
|
|
|
|
* also line comment
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
Querying
|
|
|
|
--------
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
### Periods
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```
|
|
|
|
[interval] [begin] [end]
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
interval:
|
|
|
|
every day|week|month|quarter|year
|
|
|
|
every N days|weeks|...
|
|
|
|
daily|weekly|...
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
begin:
|
|
|
|
from <spec>
|
|
|
|
end:
|
|
|
|
to <spec>
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
spec:
|
|
|
|
2004
|
|
|
|
2004/10/1
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ ledger bal|reg --period "until aug"
|
|
|
|
$ ledger bal|reg --period "last oct"
|
|
|
|
$ ledger bal|reg --period "every week"
|
|
|
|
```
|
|
|
|
{: .-setup}
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Register
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
$ ledger reg
|
|
|
|
```
|
|
|
|
{: .-setup}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
-D, --daily
|
|
|
|
-W, --weekly
|
|
|
|
-M, --monthly
|
2014-02-25 10:32:14 +00:00
|
|
|
--quarterly
|
2017-08-28 20:26:46 +00:00
|
|
|
-Y, --yearly
|
|
|
|
-s, --subtotal
|
|
|
|
--start-of-week monday
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
-S, --sort date
|
|
|
|
-S, --sort amount
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Filters
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
-b, --begin DATE
|
|
|
|
-e, --end DATE
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
-d payee =~ /pioneer/
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
-C, --cleared # (with *)
|
|
|
|
-U, --uncleared # (no *)
|
|
|
|
--pending # (with !)
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
-R, --real # ignore virtual postings (eg: "(Cash) $-400")
|
|
|
|
-L, --actual # no automated postings (eg: "= /^Income/")
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
-r, --related # show the other side
|
|
|
|
# "reg -r savings" shows where it comes from)
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
2014-06-07 14:32:02 +00:00
|
|
|
### Queries
|
|
|
|
|
|
|
|
^regex$
|
|
|
|
@payee
|
|
|
|
%tag
|
2020-05-24 03:18:17 +00:00
|
|
|
%tag=value
|
2014-06-07 14:32:02 +00:00
|
|
|
=note
|
|
|
|
#code
|
|
|
|
term and term
|
|
|
|
term or term
|
|
|
|
not term
|
|
|
|
\( term \)
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
ledger r ^expenses and @Denny's
|
|
|
|
ledger r food and @Starbucks and not dining
|
|
|
|
|
2014-02-25 10:32:14 +00:00
|
|
|
### Display
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
-n, --collapse # [register] collapse entries
|
|
|
|
# [balance] no grand total
|
|
|
|
-s, --subtotal # [balance] show sub-accounts
|
|
|
|
# [other] show subtotals
|
|
|
|
--flat
|
|
|
|
```
|
2014-02-25 10:32:14 +00:00
|
|
|
|
|
|
|
### Effective dates
|
|
|
|
|
2017-08-28 20:26:46 +00:00
|
|
|
```bash
|
|
|
|
2008/01/01=2008/01/14 Client invoice ; estimated date you'll be paid
|
|
|
|
Assets:Accounts Receivable $100.00
|
|
|
|
Income: Client name
|
|
|
|
```
|
|
|
|
{: data-line="1"}
|
|
|
|
|
|
|
|
Say you're in business. If you bill a customer, you can enter something like above.
|
|
|
|
Then, when you receive the payment, you change it to:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
2008/01/01=2008/01/15 Client invoice ; actual date money received
|
|
|
|
Assets:Accounts Receivable $100.00
|
|
|
|
Income: Client name
|
|
|
|
```
|
|
|
|
{: data-line="1"}
|
|
|
|
|
|
|
|
## References
|
|
|
|
{: .-one-column}
|
|
|
|
|
|
|
|
* <http://ledger-cli.org/3.0/doc/ledger3.html>
|
|
|
|
* <https://gist.github.com/agaviria/3317397>
|
|
|
|
{: .-also-see}
|