How to use the command 'ledger' (with examples)
The ledger
command is a powerful double-entry accounting system that allows users to manage and track their financial transactions. It provides a variety of features such as balance reports, budget reports, and statistics on financial data. This article will illustrate several use cases of the ledger
command to showcase its versatility and usefulness in financial management.
Use case 1: Print a balance report showing totals
Code:
ledger balance --file path/to/ledger.journal
Motivation:
Printing a balance report is essential for understanding the overall financial status and identifying any discrepancies in the ledger. This use case allows users to generate a comprehensive report detailing the total balances of various accounts.
Explanation:
ledger balance
: This command triggers the balance report generation inledger
.--file path/to/ledger.journal
: Specifies the path to the ledger journal file. Replacepath/to/ledger.journal
with the actual file path on your system.
Example output:
€ Euros
Assets € 1.0000
Liabilities € 0.0000
Income € 0.0000
Expenses € 0.0000
Equity:Opening € 0.0000
=============
€ 1.0000
Use case 2: List all postings in Expenses ordered by amount
Code:
ledger register expenses --sorted amount
Motivation:
Sorting expenses by amount allows users to identify and prioritize the highest costing expenditures. This use case enables users to analyze their expenses and potentially make adjustments to their budget accordingly.
Explanation:
ledger register
: Displays a register of all postings.expenses
: Filters the postings to only include the account “Expenses”.--sorted amount
: Sorts the postings by the amount in ascending order.
Example output:
2022-01-01 Grocery Store Expenses:Housing € 50.00
2022-01-05 Dining Out Expenses:Food € 100.00
2022-01-10 Utility Bill Expenses:Housing € 150.00
=========================================================
Total € 300.00
Use case 3: Print total Expenses other than Drinks and Food
Code:
ledger balance Expenses and not (Drinks or Food)
Motivation:
Focusing on specific expense categories such as Drinks and Food can help users recognize the impact of these expenses on their budget. By excluding them from the total expenses, users can gain a clearer picture of their remaining expenditures.
Explanation:
ledger balance
: Generates a balance report.Expenses
: Specifies the accounts to include in the balance report.and not (Drinks or Food)
: Excludes the accounts “Drinks” and “Food” from the balance calculation.
Example output:
€ Euros
Expenses € 200.00
Use case 4: Print a budget report
Code:
ledger budget
Motivation:
A budget report is essential for tracking expenses against predefined budget categories. This use case allows users to view their actual expenses alongside their budgeted amounts, helping them determine if they are overspending or staying within their budget.
Explanation:
ledger budget
: Generates a budget report based on the accounts and amounts specified in the ledger.
Example output:
€ Euros
Budget:Food € 150.00
====================
Expenses € 100.00
====================
Remaining € 50.00
Use case 5: Print summary information about all the postings
Code:
ledger stats
Motivation:
Getting summary information about all the postings can provide users with a quick overview of their financial transactions. This use case enables users to access aggregate data, such as the total number of postings, the number of unique accounts, and the net worth.
Explanation:
ledger stats
: Generates statistics about the ledger data, including the total number of postings, the number of unique accounts, and the net worth.
Example output:
========= Transactions ==========
Total postings: 50
Unique accounts: 12
========= Commodities ==========
Base currency: € Euros
Commodities:
- € Euros
- $ USD
- £ GBP
========= Commodities Report ==========
Total net worth: € 10,000.00