calibredb

calibredb command [options] [arguments]

calibredb is the command line interface to the calibre database. It has several sub-commands, documented below:

Global options

--dont-notify-gui

Do not notify the running calibre GUI (if any) that the database has changed. Use with care, as it can lead to database corruption!

--library-path

Path to the calibre library. Default is to use the path stored in the settings.

list

calibredb list [options]

List the books available in the calibre database.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--ascending

Sort results in ascending order

--fields, -f

The fields to display when listing books in the database. Should be a comma separated list of fields. Available fields: author_sort,authors,comments,cover,formats,identifiers,isbn,last_modified,pubdate,publisher,rating,series,series_index,size,tags,timestamp,title,uuid Default: title,authors. The special field “all” can be used to select all fields. Only has effect in the text output format.

--for-machine

Generate output that is more suitable for machine parsing. Book entries are separates using the ASCII Record Separator character (30), individual fields in an entry using the Group Separator (29) and individual filenames using the File Separator (28)

--help, -h

show this help message and exit

--limit

The maximum number of results to display. Default: all

--line-width, -w

The maximum width of a single line in the output. Defaults to detecting screen size.

--prefix

The prefix for all file paths. Default is the absolute path to the library folder.

Filter the results by the search query. For the format of the search query, please see the search related documentation in the User Manual. Default is to do no filtering.

--separator

The string used to separate fields. Default is a space.

--sort-by

The field by which to sort the results. Available fields: publisher,series_index,formats,isbn,uuid,pubdate,rating,series,timestamp,author_sort,cover,comments,identifiers,last_modified,authors,title,tags,size Default: None

--version

show program’s version number and exit

add

calibredb add [options] file1 file2 file3 ...

Add the specified files as books to the database. You can also specify directories, see the directory related options below.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--authors, -a

Set the authors of the added book(s)

--cover, -c

Path to the cover to use for the added book

--duplicates, -d

Add books to database even if they already exist. Comparison is done based on book titles.

--empty, -e

Add an empty book (a book with no formats)

--help, -h

show this help message and exit

--isbn, -i

Set the ISBN of the added book(s)

--languages, -l

A comma separated list of languages (best to use ISO639 language codes, though some language names may also be recognized)

--one-book-per-directory, -1

Assume that each directory has only a single logical book and that all files in it are different e-book formats of that book

--recurse, -r

Process directories recursively

--series, -s

Set the series of the added book(s)

--series-index, -S

Set the series number of the added book(s)

--tags, -T

Set the tags of the added book(s)

--title, -t

Set the title of the added book(s)

--version

show program’s version number and exit

remove

calibredb remove ids

Remove the books identified by ids from the database. ids should be a comma separated list of id numbers (you can get id numbers by using the list command). For example, 23,34,57-85 (when specifying a range, the last number in the range is not included).

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--version

show program’s version number and exit

add_format

calibredb add_format [options] id ebook_file

Add the ebook in ebook_file to the available formats for the logical book identified by id. You can get id by using the list command. If the format already exists, it is replaced, unless the do not replace option is specified.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--dont-replace

Do not replace the format if it already exists

--help, -h

show this help message and exit

--version

show program’s version number and exit

remove_format

calibredb remove_format [options] id fmt

Remove the format fmt from the logical book identified by id. You can get id by using the list command. fmt should be a file extension like LRF or TXT or EPUB. If the logical book does not have fmt available, do nothing.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--version

show program’s version number and exit

show_metadata

calibredb show_metadata [options] id

Show the metadata stored in the calibre database for the book identified by id. id is an id number from the list command.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--as-opf

Print metadata in OPF form (XML)

--help, -h

show this help message and exit

--version

show program’s version number and exit

set_metadata

calibredb set_metadata [options] id [/path/to/metadata.opf]

Set the metadata stored in the calibre database for the book identified by id from the OPF file metadata.opf. id is an id number from the list command. You can get a quick feel for the OPF format by using the –as-opf switch to the show_metadata command. You can also set the metadata of individual fields with the –field option. If you use the –field option, there is no need to specify an OPF file.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--field, -f

The field to set. Format is field_name:value, for example: --field tags:tag1,tag2. Use --list-fields to get a list of all field names. You can specify this option multiple times to set multiple fields. Note: For languages you must use the ISO639 language codes (e.g. en for English, fr for French and so on). For identifiers, the syntax is --field identifiers:isbn:XXXX,doi:YYYYY. For boolean (yes/no) fields use true and false or yes and no.

--help, -h

show this help message and exit

--list-fields, -l

List the metadata field names that can be used with the --field option

--version

show program’s version number and exit

export

calibredb export [options] ids

Export the books specified by ids (a comma separated list) to the filesystem. The export operation saves all formats of the book, its cover and metadata (in an opf file). You can get id numbers from the list command.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--all

Export all books in database, ignoring the list of ids.

--dont-asciiize

Normally, calibre will convert all non English characters into English equivalents for the file names. WARNING: If you turn this off, you may experience errors when saving, depending on how well the filesystem you are saving to supports unicode. Specifying this switch will turn this behavior off.

--dont-save-cover

Normally, calibre will save the cover in a separate file along with the actual e-book file(s). Specifying this switch will turn this behavior off.

--dont-update-metadata

Normally, calibre will update the metadata in the saved files from what is in the calibre library. Makes saving to disk slower. Specifying this switch will turn this behavior off.

--dont-write-opf

Normally, calibre will write the metadata into a separate OPF file along with the actual e-book files. Specifying this switch will turn this behavior off.

--formats

Comma separated list of formats to save for each book. By default all available formats are saved.

--help, -h

show this help message and exit

--replace-whitespace

Replace whitespace with underscores.

--single-dir

Export all books into a single directory

--template

The template to control the filename and directory structure of the saved files. Default is “{author_sort}/{title}/{title} - {authors}” which will save books into a per-author subdirectory with filenames containing title and author. Available controls are: {publisher, series_index, isbn, pubdate, rating, series, author_sort, languages, authors, last_modified, timestamp, title, id, tags}

--timefmt

The format in which to display dates. %d - day, %b - month, %m - month number, %Y - year. Default is: %b, %Y

--to-dir

Export books to the specified directory. Default is .

--to-lowercase

Convert paths to lowercase.

--version

show program’s version number and exit

catalog

calibredb catalog /path/to/destination.(CSV|EPUB|MOBI|XML ...) [options]

Export a catalog in format specified by path/to/destination extension. Options control how entries are displayed in the generated catalog output.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--fields

The fields to output when cataloging books in the database. Should be a comma-separated list of fields. Available fields: all, title, title_sort, author_sort, authors, comments, cover, formats, id, isbn, library_name, ondevice, pubdate, publisher, rating, series_index, series, size, tags, timestamp, uuid, languages, identifiers, plus user-created custom fields. Example: --fields=title,authors,tags Default: ‘all’ Applies to: CSV, XML output formats

--help, -h

show this help message and exit

--ids, -i

Comma-separated list of database IDs to catalog. If declared, --search is ignored. Default: all

Filter the results by the search query. For the format of the search query, please see the search-related documentation in the User Manual. Default: no filtering

--sort-by

Output field to sort on. Available fields: author_sort, id, rating, size, timestamp, title_sort Default: ‘id’ Applies to: CSV, XML output formats

--verbose, -v

Show detailed output information. Useful for debugging

--version

show program’s version number and exit

saved_searches

calibredb saved_searches [options] list

calibredb saved_searches add name search calibredb saved_searches remove name

Manage the saved searches stored in this database. If you try to add a query with a name that already exists, it will be replaced.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--version

show program’s version number and exit

add_custom_column

calibredb add_custom_column [options] label name datatype

Create a custom column. label is the machine friendly name of the column. Should not contain spaces or colons. name is the human friendly name of the column. datatype is one of: rating, int, text, float, comments, datetime, composite, bool, enumeration, series

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--display

A dictionary of options to customize how the data in this column will be interpreted. This is a JSON string. For enumeration columns, use --display=“{“enum_values”:[“val1”, “val2”]}” There are many options that can go into the display variable.The options by column type are: composite: composite_template, composite_sort, make_category,contains_html, use_decorations datetime: date_format enumeration: enum_values, enum_colors, use_decorations int, float: number_format text: is_names, use_decorations The best way to find legal combinations is to create a custom column of the appropriate type in the GUI then look at the backup OPF for a book (ensure that a new OPF has been created since the column was added). You will see the JSON for the “display” for the new column in the OPF.

--help, -h

show this help message and exit

--is-multiple

This column stores tag like data (i.e. multiple comma separated values). Only applies if datatype is text.

--version

show program’s version number and exit

custom_columns

calibredb custom_columns [options]

List available custom columns. Shows column labels and ids.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--details, -d

Show details for each column.

--help, -h

show this help message and exit

--version

show program’s version number and exit

remove_custom_column

calibredb remove_custom_column [options] label

Remove the custom column identified by label. You can see available columns with the custom_columns command.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--force, -f

Do not ask for confirmation

--help, -h

show this help message and exit

--version

show program’s version number and exit

set_custom

calibredb set_custom [options] column id value

Set the value of a custom column for the book identified by id. You can get a list of ids using the list command. You can get a list of custom column names using the custom_columns command.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--append, -a

If the column stores multiple values, append the specified values to the existing ones, instead of replacing them.

--help, -h

show this help message and exit

--version

show program’s version number and exit

restore_database

calibredb restore_database [options]

Restore this database from the metadata stored in OPF files in each directory of the calibre library. This is useful if your metadata.db file has been corrupted.

WARNING: This command completely regenerates your database. You will lose all saved searches, user categories, plugboards, stored per-book conversion settings, and custom recipes. Restored metadata will only be as accurate as what is found in the OPF files.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--really-do-it, -r

Really do the recovery. The command will not run unless this option is specified.

--version

show program’s version number and exit

check_library

calibredb check_library [options]

Perform some checks on the filesystem representing a library. Reports are invalid_titles, extra_titles, invalid_authors, extra_authors, missing_formats, extra_formats, extra_files, missing_covers, extra_covers, failed_folders

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--csv, -c

Output in CSV

--help, -h

show this help message and exit

--ignore_extensions, -e

Comma-separated list of extensions to ignore. Default: all

--ignore_names, -n

Comma-separated list of names to ignore. Default: all

--report, -r

Comma-separated list of reports. Default: all

--version

show program’s version number and exit

list_categories

calibredb list_categories [options]

Produce a report of the category information in the database. The information is the equivalent of what is shown in the tags pane.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--categories, -r

Comma-separated list of category lookup names. Default: all

--csv, -c

Output in CSV

--help, -h

show this help message and exit

--item_count, -i

Output only the number of items in a category instead of the counts per item within the category

--quote, -q

The character to put around the category value in CSV mode. Default is quotes (”).

--separator, -s

The string used to separate fields in CSV mode. Default is a comma.

--version

show program’s version number and exit

--width, -w

The maximum width of a single line in the output. Defaults to detecting screen size.

backup_metadata

calibredb backup_metadata [options]

Backup the metadata stored in the database into individual OPF files in each books directory. This normally happens automatically, but you can run this command to force re-generation of the OPF files, with the –all option.

Note that there is normally no need to do this, as the OPF files are backed up automatically, every time metadata is changed.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--all

Normally, this command only operates on books that have out of date OPF files. This option makes it operate on all books.

--help, -h

show this help message and exit

--version

show program’s version number and exit

clone

calibredb clone path/to/new/library

Create a clone of the current library. This creates a new, empty library that has all the same custom columns, virtual libraries and other settings as the current library.

The cloned library will contain no books. If you want to create a full duplicate, including all books, then simply use your filesystem tools to copy the library folder.

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--version

show program’s version number and exit

embed_metadata

calibredb embed_metadata [options] book_id

Update the metadata in the actual book files stored in the calibre library from the metadata in the calibre database. Normally, metadata is updated only when exporting files from calibre, this command is useful if you want the files to be updated in place. Note that different file formats support different amounts of metadata. You can use the special value ‘all’ for book_id to update metadata in all books. You can also specify many book ids separated by spaces and id ranges separated by hyphens. For example: calibredb embed_metadata 1 2 10-15 23

Whenever you pass arguments to calibredb that have spaces in them, enclose the arguments in quotation marks.

--help, -h

show this help message and exit

--only-formats, -f

Only update metadata in files of the specified format. Specify it multiple times for multiple formats. By default, all formats are updated.

--version

show program’s version number and exit