LinuxCommandLibrary

gnucash-cli

Process GnuCash data from the command line

TLDR

Get quotes for currencies and stocks specified in a file and print them

$ gnucash-cli [[-Q|--quotes]] get [path/to/file.gnucash]
copy

Generate a financial report of a specific type, specified by --name
$ gnucash-cli --report run --name "[Balance Sheet]" [path/to/file.gnucash]
copy

SYNOPSIS

gnucash-cli [OPTION]... COMMAND [ARG]...

PARAMETERS

--help
    Display help message and exit

--version
    Print version information and exit

--verbose
    Enable verbose output

--log=LEVEL
    Set log level (e.g., debug, info, warn)

--book=FILE
    Open book from specified file path

--book-id=GUID
    Open book by unique identifier

--add-default-session
    Add a default session to the book

help
    Show help for commands

version
    Display gnucash-cli version

listfilesessions
    List all sessions for a book

addfilesession URI [NAME]
    Add a named session to URI

deletefilesession URI
    Delete session from URI

session-info URI
    Get detailed session information

export
    Export data/reports (requires --input, --output)

gnc-fq-helper
    Online quote retrieval helper

DESCRIPTION

gnucash-cli is a powerful command-line tool integrated with the GnuCash open-source accounting software. It enables users to perform batch operations on financial data files without launching the full graphical interface, ideal for automation, scripting, server deployments, and headless environments.

Core capabilities include managing file sessions (listing, adding, deleting), querying session details, exporting accounts, transactions, or reports to formats like CSV, HTML, or SQL, and generating custom reports via Scheme scripts. Books can be specified by file path or GUID, with support for SQL backends. Logging, verbosity, and debug levels are configurable for troubleshooting.

This tool bridges GnuCash's robust double-entry engine with shell scripting, facilitating tasks like periodic backups, data migrations, reconciliation automation, and integration with cron jobs or CI/CD pipelines. It requires GnuCash libraries and preserves data integrity with session locking.

CAVEATS

Requires exclusive access to data files during operations; SQL books need proper KVP settings. Not all GUI features are supported. Debug mode may expose sensitive data.

COMMON EXPORT USAGE

gnucash-cli export --book=book.gnucash --input=/accounts --output=export.csv --format=csv
Exports account transactions to CSV.

REQUIREMENTS

GnuCash >=4.5, Guile Scheme interpreter. Install via package managers: apt install gnucash or equivalent.

HISTORY

Introduced in GnuCash 4.5 (March 2021) by the GnuCash development team to address the lack of CLI support in prior versions, enhancing automation for enterprise and scripted use.

SEE ALSO

gnucash(1), guile(1), sql(1)

Copied to clipboard