1.2 Command-line usage

This section contains extra information about using LilyPond on the command-line. This may be desirable to pass extra options to the program. In addition, there are certain extra ‘helper’ programs (such as midi2ly) which are only available on the command-line.

By ‘command-line’, we mean the command line in the operating system. Windows users might be more familiar with the terms ‘DOS shell’ or ‘command shell’. MacOS X users might be more familiar with the terms ‘terminal’ or ‘console’. Some additional setup is required for MacOS X users; please see MacOS X.

Describing how to use this part of an operating system is outside the scope of this manual; please consult other documentation on this topic if you are unfamiliar with the command-line.

Invoking lilypond

The lilypond executable may be called as follows from the command line.

lilypond [option]… file

When invoked with a filename that has no extension, the ‘.ly’ extension is tried first. To read input from stdin, use a dash (-) for file.

When ‘filename.ly’ is processed it will produce ‘filename.ps’ and ‘filename.pdf’ as output. Several files can be specified; they will each be processed independently. 1

If ‘filename.ly’ contains more than one \book block, then the rest of the scores will be output in numbered files, starting with ‘filename-1.pdf’. In addition, the value of output-suffix will be inserted between the basename and the number. An input file containing

#(define output-suffix "violin")
\score { … }
#(define output-suffix "cello")
\score { … }

will output base-violin.pdf’ and base-cello-1.pdf’.

Using LilyPond with standard shell features

Since LilyPond is a command line application, features of the ‘shell’ used for calling LilyPond can also be put to good use.

For example:

lilypond *.ly

will process all LilyPond files in the current directory.

Redirecting the console output (e.g. to a file) may also be useful:

lilypond file.ly 1> stdout.txt

lilypond file.ly 2> stderr.txt

lilypond file.ly &> all.txt

Redirects ‘normal’ output, ‘errors’ only or ‘everything’, respectively, to a text file. Consult the documentation for your particular shell, Command (Windows), Terminal or Console applications (MacOS X) to see if output redirection is supported or if the syntax is different.

The following example searches and processes all input files in the current directory and all directories below it recursively. The output files will be located in the same directory that the command was run in, rather than in the same directories as the original input files.

find . -name '*.ly' -exec lilypond '{}' \;

This should also work for MacOS X users.

A Windows user would run;

forfiles /s /M *.ly /c "cmd /c lilypond @file"

entering these commands in a command prompt usually found under Start > Accessories > Command Prompt or for version 8 users, by typing in the search window ‘command prompt’.

Alternatively, an explicit path to the top-level of your folder containing all the sub-folders that have input files in them can be stated using the /p option;

forfiles /s /p C:\Documents\MyScores /M *.ly /c "cmd /c lilypond @file"

If there are spaces in the path to the top-level folder, then the whole path needs to be inside double quotes;

forfiles /s /p "C:\Documents\My Scores" /M *.ly /c "cmd /c lilypond @file"

Basic command line options for LilyPond

The following options are supported:

-d, --define-default=var=val

See Advanced command line options for LilyPond.

-e, --evaluate=expr

Evaluate the Scheme expr before parsing any ‘.ly’ files. Multiple ‘-e’ options may be given, they will be evaluated sequentially.

The expression will be evaluated in the guile-user module, so if you want to use definitions in expr, use

lilypond -e '(define-public a 42)'

on the command-line, and include

#(use-modules (guile-user))

at the top of the .ly file.

Note: Windows users must use double quotes instead of single quotes.

-E, --eps

Generate EPS files.

-f, --format=format

which formats should be written. Choices for format are ps, pdf, and png.

Example: lilypond -fpng filename.ly

For svg and eps formats use the -dbackend option. See Advanced command line options for LilyPond.

-h, --help

Show a summary of usage.

-H, --header=FIELD

Dump a header field to file ‘BASENAME.FIELD’.

-i, --init=file

Set init file to file (default: ‘init.ly’).

-I, --include=directory

Add directory to the search path for input files.

Multiple -I options may be given. The search will start in the first defined directory, and if the file to be included is not found the search will continue in subsequent directories.

Note: Using the tilde character (~) with the -I switch may produce unexpected results in some shells.

Windows users will need to include a trailing slash for the directory’s path.

-j, --jail=user,group,jail,dir

Run lilypond in a chroot jail.

The ‘--jail’ option provides a more flexible alternative to ‘-dsafe’, when LilyPond formatting is being provided via a web server, or whenever LilyPond executes commands sent by external sources (see Advanced command line options for LilyPond).

It works by changing the root of lilypond to jail just before starting the actual compilation process. The user and group are then changed to match those provided, and the current directory is changed to dir. This setup guarantees that it is not possible (at least in theory) to escape from the jail. Note that for ‘--jail’ to work, lilypond must be run as root, which is usually accomplished in a safe way using sudo.

Setting up a jail can be a relatively complex matter, as we must be sure that LilyPond is able to find whatever it needs to compile the source inside the jail itself. A typical chroot jail will comprise the following steps:

Setting up a separate filesystem

A separate filesystem should be created for LilyPond, so that it can be mounted with safe options such as noexec, nodev, and nosuid. In this way, it is impossible to run executables or to write directly to a device from LilyPond. If you do not want to create a separate partition, just create a file of reasonable size and use it to mount a loop device. A separate filesystem also guarantees that LilyPond cannot write more space than it is allowed.

Setting up a separate user

A separate user and group (say, lily/lily) with low privileges should be used to run LilyPond inside the jail. There should be a single directory writable by this user, which should be passed in dir.

Preparing the jail

LilyPond needs to read a number of files while running. All these files are to be copied into the jail, under the same path they appear in the real root filesystem. The entire content of the LilyPond installation (e.g., ‘/usr/share/lilypond’) should be copied.

If problems arise, the simplest way to trace them down is to run LilyPond using strace, which will allow you to determine which files are missing.

Running LilyPond

In a jail mounted with noexec it is impossible to execute any external program. Therefore LilyPond must be run with a backend that does not require any such program. As we have already mentioned, it must be run with superuser privileges (which, of course, it will lose immediately), possibly using sudo. It is also good practice to limit the number of seconds of CPU time LilyPond can use (e.g., using ulimit -t), and, if your operating system supports it, the amount of memory that can be allocated. Also see LilyPond in chroot jail.

-l, --loglevel=LEVEL

Set the verbosity of the console output to LEVEL. Possible values are:


No output at all, not even error messages.


Only error messages, no warnings or progress messages.


Warnings and error messages, no progress.


Basic progress messages (success), warnings and errors.


All progress messages, warnings and errors.

INFO (default)

Progress messages, warnings, errors and further execution information.


All possible messages, including verbose debug output.

-o, --output=FILE or FOLDER

Set the default output file to FILE or, if a folder with that name exists, direct the output to FOLDER, taking the file name from the input file. The appropriate suffix will be added (e.g. .pdf for pdf) in both cases.

-O, --pspdfopt

If you do not use pspdfopt or if you use the parameter size, lilypond will try to generate a very small ps/eps/pdf document.

If you use the parameter TeX, lilypond will produce files that are optimized for inclusion in PdfTeX, LuaTeX or XeTeX documents.

If you want to include more than one pdf generated by lilypond into a TeX document, use TeX-GS and postprocess the pdf generated by TeX with ghostscript.


Generate PostScript.


Generate pictures of each page, in PNG format. This implies ‘--ps’. The resolution in DPI of the image may be set with


Generate PDF. This implies ‘--ps’.

-v, --version

Show version information.

-V, --verbose

Be verbose: show full paths of all files read, and give timing information.

-w, --warranty

Show the warranty with which GNU LilyPond comes. (It comes with NO WARRANTY!)

Advanced command line options for LilyPond


–define-default=[option-name]=[value] This sets the equivalent internal Scheme function to value. For example;


If a value is not supplied, then the default value is used. The prefix no- may be added to option-name to switch ‘off’ an option. For example;


is the same as


The following are supported along with their respective default values:

anti-alias-factor1Render at a higher resolution (using the given factor) and scale down the result to prevent ‘jaggies’ in PNG images.
aux-files#tCreate .tex, .texi and .count files when used with the eps backend option.
backendpsThis is the default setting. Postscript files (default) include TTF, Type1 and OTF fonts. No ‘subsetting’ of these fonts is done. Be aware that using ‘oriental’ character sets can lead to very large file sizes.
epsUsed as default by the lilypond-book command. This dumps every page as both a single file with all pages and fonts included and as separate encapsulated postscript files for each page but without fonts included.
nullDo not output a printed score. This has the same effect as -dno-print-pages.
scmThis dumps out the raw, internal Scheme-based drawing commands.
svgScalable Vector Graphics. A single SVG file is created for every page of output. Music glyphs are encoded as vector graphics, but text fonts are not embedded in the SVG files. Any SVG viewer will therefore need the relevant text fonts to be available to it for proper rendering of both text and lyrics. It is recommended to not use font ‘lists’ or ‘aliases’ in case an SVG viewer is unable to handle them. When using Web Open Font Format (WOFF) files the additional --svg-woff switch is required.
check-internal-types#fCheck every property assignment for types.
clip-systems#fExtract music fragments out of a score. This requires that the clip-regions function has been defined within the \layout block. See Extracting fragments of music. No fragments are extracted though if used with the ‘-dno-print-pages’ option.
crop#fMatch the size of the normal output to the typeset image.
datadirPrefix for data files (read-only).
debug-gc#fDump memory debugging statistics.
debug-gc-assert-parsed-dead#fFor memory debugging: Ensure that all references to parsed objects are dead. This is an internal option, and is switched on automatically for `-ddebug-gc'.
debug-lexer#fDebug the flex lexer.
debug-page-breaking-scoring#fDump scores for many different page breaking configurations.
debug-parser#fDebug the bison parser.
debug-property-callbacks#fDebug cyclic callback chains.
debug-skylines#fDebug skylines.
delete-intermediate-files#tDelete the unusable, intermediate .ps files created during compilation.
dump-cpu-profile#fDump timing information (system-dependent).
dump-profile#fDump memory and time information for each file.
dump-signatures#fDump output signatures of each system. Used for regression testing.
embed-source-code#fEmbed the LilyPond source files inside the generated PDF document.
eps-box-padding#fPad left edge of the output EPS bounding box by the given amount (in mm).
font-export-dir#f [dir]Directory for exporting fonts as PostScript files.
gs-load-fonts#fLoad fonts via Ghostscript.
gs-load-lily-fonts#fLoad only the LilyPond fonts via Ghostscript.
gs-never-embed-fonts#fMake Ghostscript embed only TrueType fonts and no other font format.
gui#fRuns silently and redirect all output to a log file.

Note to Windows users: By default lilypond.exe outputs all progress information to the command window, lilypond-windows.exe does not and returns a prompt, with no progress information, immediately at the command line. The ‘-dgui’ option can be used in this case to redirect output to a log file.

help#fShow this help.
include-book-title-preview#tInclude book titles in preview images.
include-eps-fonts#tInclude fonts in separate-system EPS files.
include-settings#fInclude file for global settings, this is included before the score is processed.
job-count#fProcess in parallel, using the given number of jobs.
log-file#f [file]If string FOO is given as a second argument, redirect output to the log file FOO.log.
max-markup-depth1024Maximum depth for the markup tree. If a markup has more levels, assume it will not terminate on its own, print a warning and return a null markup instead.
midi-extension"midi"Set the default file extension for MIDI output file to given string.
music-strings-to-paths#fConvert text strings to paths when glyphs belong to a music font.
paper-size\"a4\"Set default paper size. Note the string must be enclosed in escaped double quotes.
pixmap-formatpng16mSet GhostScript’s output format for pixel images.
point-and-click#tAdd ‘point & click’ links to PDF and SVG output. See Point and click.
preview#fCreate preview images in addition to normal output.

This option is supported by all backends; pdf, png, ps, eps and svg, but not scm. It generates an output file, in the form myFile.preview.extension, containing the titles and the first system of music. If \book or \bookpart blocks are used, the titles of \book, \bookpart or \score will appear in the output, including the first system of every \score block if the \paper variable print-all-headers is set to #t.

To suppress the usual output, use the ‘-dprint-pages’ or ‘-dno-print-pages’ options according to your requirements.

print-pages#tGenerate full pages, the default. ‘-dno-print-pages’ is useful in combination with ‘-dpreview’ or ‘-dcrop’.
profile-property-accesses#fKeep statistics of get_property() function calls.
protected-scheme-parsing#tContinue when errors in inline scheme are caught in the parser. If set to #f, halt on errors and print a stack trace.
read-file-list#f [file]Specify name of a file which contains a list of input files to be processed.
relative-includes#fWhen processing an \include command, look for the included file relative to the current file (instead of the root file).
resolution101Set resolution for generating PNG pixmaps to given value (in dpi).
safe#fDo not trust the .ly input.

When LilyPond formatting is available through a web server, either the ‘--safe’ or the ‘--jail’ option MUST be passed. The ‘--safe’ option will prevent inline Scheme code from wreaking havoc, e.g,

#(s ystem "rm -rf /")  % too dangerous to write correctly
  c4^$(ly:gulp-file "/etc/passwd") % malicious but not destructive

The ‘-dsafe’ option works by evaluating in-line Scheme expressions in a special safe module. This is derived from GUILE ‘safe-r5rs’ module, but also adds a number of functions of the LilyPond API which are listed in ‘scm/safe-lily.scm’.

In addition, safe mode disallows \include directives and disables the use of backslashes in TeX strings. It is also not possible to import LilyPond variables into Scheme while in safe mode.

-dsafe’ does not detect resource overuse, so it is still possible to make the program hang indefinitely, for example by feeding cyclic data structures into the backend. Therefore, if using LilyPond on a publicly accessible webserver, the process should be limited in both CPU and memory usage.

Safe mode will prevent many useful LilyPond snippets from being compiled.

The ‘--jail’ is an even more secure alternative, but requires more work to set up. See Basic command line options for LilyPond.

separate-log-files#fFor input files FILE1.ly, FILE2.ly, etc. output log data to files FILE1.log, FILE2.log
show-available-fonts#fList available font names.
strict-infinity-checking#fForce a crash on encountering Inf and NaN floating point exceptions.
strip-output-dir#tDon’t use directories from input files while constructing output file names.
strokeadjust#fForce PostScript stroke adjustment. This option is mostly relevant when a PDF is generated from PostScript output (stroke adjustment is usually enabled automatically for low-resolution bitmap devices). Without this option, PDF previewers tend to produce widely inconsistent stem widths at resolutions typical for screen display. The option does not noticeably affect print quality and causes large file size increases in PDF files.
svg-woff#fThis option is required when using Web Open Font Format (WOFF) font files with the backend svg command. A single SVG file is created for every page of output. Apart from LilyPond’s own music glyphs, no other font information will be included. Any SVG viewer will therefore require the fonts be available to it for the proper rendering of both text and lyrics. It is also recommended not to use any font ‘aliases’ or ‘lists’ in case the SVG viewer cannot handle them.
trace-memory-frequency#fRecord Scheme cell usage this many times per second. Dump the results to FILE.stacks and FILE.graph.
trace-scheme-coverage#fRecord coverage of Scheme files in FILE.cov.
verbose#fVerbose output, i.e. loglevel at DEBUG (read-only).
warning-as-error#fChange all warning and ‘programming error’ messages into errors.

Environment variables

lilypond recognizes the following environment variables:


This specifies a directory where locale messages and data files will be looked up by default. The directory should contain subdirectories called ‘ly/’, ‘ps/’, ‘tex/’, etc.


This selects the language for the warning messages.


The default loglevel. If LilyPond is called without an explicit loglevel (i.e. no ‘--loglevel’ command line option), this value is used.


A variable, as a percentage, that tunes memory management behavior. A higher values means the program uses more memory, a smaller value means more CPU time is used. The default value is 70.

LilyPond in chroot jail

Setting up the server to run LilyPond in a chroot jail is a complicated task. The steps are listed below. Examples in the steps are from Ubuntu GNU/Linux, and may require the use of sudo as appropriate.

Example script for 32-bit Ubuntu 8.04

## defaults set here

# the prefix (without the leading slash!)
# the directory where lilypond is installed on the system

adduser $username
dd if=/dev/zero of=$loopfile bs=1k count=200000
mkdir $jaildir
losetup $loopdevice $loopfile
mkfs -t ext3 $loopdevice 200000
mount -t ext3 $loopdevice $jaildir
mkdir $jaildir/lilyhome
chown $username $jaildir/lilyhome
cd $jaildir

mkdir -p bin usr/bin usr/share usr/lib usr/share/fonts $lilyprefix tmp
chmod a+w tmp

cp -r -L $lilydir $lilyprefix
cp -L /bin/sh /bin/rm bin
cp -L /usr/bin/convert /usr/bin/gs usr/bin
cp -L /usr/share/fonts/truetype usr/share/fonts

# Now the library copying magic
for i in "$lilydir/usr/bin/lilypond" "$lilydir/usr/bin/guile" "/bin/sh"  \
  "/bin/rm" "/usr/bin/gs" "/usr/bin/convert"; do ldd $i | sed 's/.*=>  \
    \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/' | sed  \
      's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/'  \
        | sed '/.*=>.*/d'; done | sh -s

# The shared files for ghostscript...
      cp -L -r /usr/share/ghostscript usr/share
# The shared files for ImageMagick
      cp -L -r /usr/lib/ImageMagick* usr/lib

### Now, assuming that you have test.ly in /mnt/lilyloop/lilyhome,
### you should be able to run:
### Note that /$lilyprefix/bin/lilypond is a script, which sets the
### LD_LIBRARY_PATH - this is crucial
      /$lilyprefix/bin/lilypond -jlily,lily,/mnt/lilyloop,/lilyhome test.ly


[1] The status of GUILE is not reset after processing a .ly file, so be careful not to change any system defaults from within Scheme.

Other languages: català, deutsch, español, français, magyar, italiano, 日本語.
About automatic language selection.

LilyPond — Usage v2.19.84 (development-branch).