Every tool in SAGA GIS — all of its terrain, hydrology, grid and geostatistics libraries — can be run without opening the SAGA graphical interface at all. The vehicle is saga_cmd, SAGA’s official command-line interface, which ships with every SAGA installation. If you need to process a folder of DEMs overnight, reproduce an analysis exactly, or let another program drive SAGA, saga_cmd is the layer you will use. This guide explains the command pattern, shows you how to read any tool’s parameters, and walks through one complete example taken from SAGA’s official tool documentation.
What saga_cmd is, and where it lives
saga_cmd is not a separate download. On Windows it sits in the SAGA installation folder alongside the graphical program — in the folder created by the installer, or in the folder you unzipped the portable package into (see SAGA for Windows). On macOS it is part of the official Mac package covered in our Mac guide, and Linux packages place it on the system in the usual way for command-line tools (see SAGA for Linux). If SAGA runs on your machine, saga_cmd is already there; open a terminal in — or pointing at — that installation and you are ready.
The interface matters beyond interactive scripting. Other software drives SAGA through this same command-line layer: the R package RSAGA, for example, works by running SAGA’s command-line version, and the automation options compared in our SAGA in QGIS hub all ultimately rest on the tools saga_cmd exposes. Learning the pattern once pays off in every direction.
The command pattern
Every saga_cmd call has the same shape:
saga_cmd <library> <tool number> -PARAMETER=value -PARAMETER=value ...
You name the tool library (for example ta_morphometry for terrain morphometry), then the tool’s number within that library, then its parameters as -NAME=value pairs. Input files, output files and options are all parameters; there is no separate syntax for them. Run saga_cmd with a library and tool number and no parameters, and it answers with that tool’s full usage text — every parameter, its type, its choices and its defaults. That usage text is exactly what SAGA’s official tool documentation reproduces for each tool, so the documentation and the program in front of you can never disagree for long: when in doubt, ask the tool.
A complete, documented example: slope, aspect, curvature
The example below is the Slope, Aspect, Curvature tool from the terrain morphometry library, as documented in the official SAGA 9.12.0 tool documentation (ta_morphometry tool 0). It computes slope, aspect and — depending on the method — curvature grids from an elevation grid:
saga_cmd ta_morphometry 0 -ELEVATION=dem.sgrd -SLOPE=slope.sgrd -ASPECT=aspect.sgrd -METHOD=6 -UNIT_SLOPE=1 -UNIT_ASPECT=1
What each parameter means, following the documentation:
-ELEVATION— the input grid: your DEM, in SAGA’s native grid format.-SLOPE— the output grid for slope. This is the one output the tool always produces.-ASPECT— an optional output grid for aspect. The documentation notes that aspect angles start at 0 for the north direction and increase clockwise. Leave the parameter out and no aspect grid is written.-METHOD— the algorithm used. The documentation lists nine choices, numbered 0 to 8, from maximum slope (Travis et al. 1975) through least-squares fitted plane (Horn 1981) to the 10-parameter third-order polynomials of Haralick and Florinsky. The default, 6, is the 9-parameter second-order polynomial of Zevenbergen & Thorne (1987) — a sound default for general terrain work.-UNIT_SLOPE— the slope unit: 0 = radians (the default), 1 = degree, 2 = percent rise. Most GIS users want degrees, which is why the example sets 1.-UNIT_ASPECT— the aspect unit: 0 = radians (default) or 1 = degree.
The same tool can also produce a family of optional curvature outputs — general, profile, plan, tangential, longitudinal and cross-sectional curvature, among others — each under its own parameter (-C_GENE, -C_PROF, -C_PLAN, -C_TANG, -C_LONG, -C_CROS). You request only the ones you need; unrequested outputs are simply not written. That pattern — one required input, named outputs, optional extras, and a method choice with a documented default — repeats across SAGA’s tool libraries, so once you can read one tool’s documentation page, you can drive any of them.
About the files: .sgrd and .sdat
saga_cmd reads and writes SAGA’s native formats by default. A SAGA grid is a pair of files: the .sgrd header you name on the command line, and a .sdat data file written next to it. Other software, including GDAL-based tools, reads the .sdat half. Remembering which half is which saves real confusion when scripts hand files to other programs — the same point that trips up QGIS users in our NextGen troubleshooting guide.
Batch processing: the reason the command line exists
The payoff for learning the pattern is repetition. A slope calculation you have run once can be applied to every DEM in a folder with a short shell loop that changes only the input and output names:
for f in dems/*.sgrd; do
saga_cmd ta_morphometry 0 -ELEVATION="$f" -SLOPE="out/$(basename "$f" .sgrd)_slope.sgrd" -UNIT_SLOPE=1
done
Every file gets identical settings, the run can be logged, and the whole job can be repeated next month on new data by re-running the script. That reproducibility is why scripted routes — saga_cmd directly, or PySAGA from Python — are the standard approach for production terrain pipelines, while the SAGA GUI and the QGIS NextGen provider serve interactive exploration. Choose per task, not per loyalty: explore in the GUI, note the tool and parameters, then automate the repetition here.
Getting started
You need nothing beyond a working SAGA installation from the download page. Open a terminal, run saga_cmd with no arguments to see the libraries your version offers, pick a tool, and ask it for its parameters. If saga_cmd answers, you also hold a diagnostic trump card: a SAGA that works from the command line but not through QGIS has a configuration problem, not an installation problem — the distinction at the heart of our troubleshooting guide.
