Call QGIS geoprocessing tools from command line (terminal, bash-script)

Starting with the release of QGIS 3.14 there is a real QGIS command line mode to use QGIS Processing Algorithms (including GDAL, SAGA and GRASS). It's called qgis_process. See the change log and search for the new feature: New standalone console tool for running processing algorithms.


If you run a QGIS Processing tool from the toolbox, you can then open the Processing History dialog from the Processing menu. Clicking any item in the history will show you an equivalent Python command in the lower half of this dialog.

You can then copy this command and paste into a Python script, which can be called directly from the terminal/bash shell.

There is some standard PyQGIS setup calls you need to make at the start of your script in order to initialise QGIS. This is described in detail in this answer: Using QGIS3 Processing algorithms from standalone PyQGIS scripts (outside of GUI)