Skip to content

Instantly share code, notes, and snippets.

@agaviria
Created August 10, 2012 20:03
Show Gist options
  • Save agaviria/3317397 to your computer and use it in GitHub Desktop.
Save agaviria/3317397 to your computer and use it in GitHub Desktop.
Collection of ledger-cli commands
# comments example for .dat or .ledger files
@smallexample
; This is a single line comment,
# and this,
% and this,
| and this,
* and this.
# If you have a deeply nested tree of accounts,
# it may be convenient to define an alias, for example:
@smallexample
alias Dining=Expenses:Entertainment:Dining
alias Checking=Assets:Credit Union:Joint Checking Account
# prints budget with % target column
ledger -f fin.dat -p "june" budget
# Provides ledger balance until the month of "i.e. August"
# aug could be replaced by any prefix for monthly calendar.
# ledger bal -f YOURFILENAME --period "until aug"
# Provides a balance of account type "i.e. assets, expenses"
ledger -f YOURFILENAME balance assets:checking
ledger -f YOURFILENAME register expenses:food
# See account subtotals for any postings related to a specific fund
@smallexample
ledger --code-as-payee -P reg ^Assets
@end smallexample
# Or to see a particular funds expenses, the @samp{School} fund in this case
@smallexample
ledger --code-as-payee -P reg ^Expenses @@School
@end smallexample
# Most times this is more than you want. Limiting the results to specific
# accounts is as easy as entering the names of the accounts after the
# command.
@smallexample
20:37:53 ~/ledger/test/input > ledger balance -f FILENAME Auto MasterCard
$ 5,500.00 Expenses:Auto
$ -20.00 Liabilities:MasterCard
--------------------
$ 5,480.00
20:39:21 ~/ledger/test/input >
@end smallexample
# You can use general regular expressions in nearly anyplace Ledger needs a string:
@smallexample
20:40:28 ~/ledger/test/input > ledger balance -f FILENAME ^Bo
21:13:29 ~/ledger/test/input > ledger balance -f FILENAME Bo
$ 20.00 Expenses:Books
@end smallexample
# The first example looks for any account starting with ``Bo'', of which
# there are none. The second looks for any account with ``Bo'', which is
@samp{Expenses:Books}.
# If you want to know exactly how much you have spent in a particular
# account on a particular payee, the following are equivalent:
@smallexample
> ledger balance Auto:Fuel and Chevron
> ledger balance --limit "(account=~/Fuel/) & (payee=~/Chev/)"
@end smallexample
# @noindent will show you the amount expended on gasoline at Chevron.
# The second example is the first example of the very power expression
# language available to shape reports. The first example may be easier to
# remember, but learning to use the second will open up far more
# possibilities.
# If you want to exclude specific accounts from the report, you can
# exclude multiple accounts with parentheses:
@smallexample
ledger -s bal Expenses and not \(Expenses:Drinks or Expenses:Candy or Expenses:Gifts\)
@end smallexample
# A query such as the following shows all expenses since last
# October, sorted by total:
@example
ledger -b "last oct" -s -S T bal ^expenses
@end example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment