2017-09-12 07:13:26 +00:00
+++
title = "CLI usage"
2019-11-26 19:18:59 +00:00
weight = 2
2017-09-12 07:13:26 +00:00
+++
2019-08-13 18:15:56 +00:00
Zola only has 4 commands: `init` , `build` , `serve` and `check` .
2017-09-27 14:37:17 +00:00
2019-11-26 19:30:30 +00:00
You can view the help for the whole program by running `zola --help` and
that for a specific command by running `zola <cmd> --help` .
2017-09-27 14:37:17 +00:00
## init
2019-08-13 18:15:56 +00:00
Creates the directory structure used by Zola at the given directory after asking a few basic configuration questions.
2019-11-26 19:30:30 +00:00
Any choices made during these prompts can be easily changed by modifying `config.toml` .
2017-09-27 14:37:17 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola init my_site
2019-08-13 17:56:57 +00:00
$ zola init
2017-09-27 14:37:17 +00:00
```
2019-11-26 19:30:30 +00:00
If the `my_site` directory already exists, Zola will only populate it if it contains only hidden files (dotfiles are ignored). If no `my_site` argument is passed, Zola will try to populate the current directory.
2019-08-13 17:56:57 +00:00
You can initialize a git repository and a Zola site directly from within a new folder:
```bash
$ git init
$ zola init
```
2017-09-27 14:37:17 +00:00
## build
2019-11-26 19:30:30 +00:00
This will build the whole site in the `public` directory (if this directory already exists, it is overwritten).
2017-09-27 14:37:17 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola build
2017-09-27 14:37:17 +00:00
```
2017-10-05 01:56:13 +00:00
You can override the config `base_url` by passing a new URL to the `base-url` flag.
```bash
2018-10-18 21:09:32 +00:00
$ zola build --base-url $DEPLOY_URL
2017-10-05 01:56:13 +00:00
```
2018-08-05 08:29:53 +00:00
This is useful for example when you want to deploy previews of a site to a dynamic URL, such as Netlify
2017-10-19 11:48:50 +00:00
deploy previews.
2019-11-26 19:30:30 +00:00
You can override the default output directory `public` by passing another value to the `output-dir` flag.
2018-03-16 18:11:08 +00:00
2017-12-29 18:25:06 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola build --output-dir $DOCUMENT_ROOT
2017-12-29 18:25:06 +00:00
```
2020-01-21 19:52:24 +00:00
You can point to a config file other than `config.toml` like so (note that the position of the `config` option is important):
2018-03-16 18:11:08 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola --config config.staging.toml build
2018-03-16 18:11:08 +00:00
```
2020-01-21 19:52:24 +00:00
You can also process a project from a different directory with the `root` flag. If building a project 'out-of-tree' with the `root` flag, you may want to combine it with the `output-dir` flag. (Note that like `config` , the position is important):
```bash
$ zola --root /path/to/project build
```
2019-11-26 19:30:30 +00:00
By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
2019-08-24 20:23:08 +00:00
2017-09-27 14:37:17 +00:00
## serve
This will build and serve the site using a local server. You can also specify
the interface/port combination to use if you want something different than the default (`127.0.0.1:1111`).
2019-11-26 19:30:30 +00:00
You can also specify different addresses for the interface and base_url using `--interface` and `-u` /`--base-url`, respectively, if for example you are running Zola in a Docker container.
2018-02-02 16:18:07 +00:00
2019-07-04 21:42:37 +00:00
Use the `--open` flag to automatically open the locally hosted instance in your
web browser.
2020-09-04 20:53:31 +00:00
In the event you don't want Zola to run a local web server, you can use the `--watch-only` flag.
2018-11-01 22:36:47 +00:00
2019-11-26 19:30:30 +00:00
Before starting, Zola will delete the `public` directory to start from a clean slate.
2019-01-07 18:24:08 +00:00
2017-09-27 14:37:17 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola serve
$ zola serve --port 2000
$ zola serve --interface 0.0.0.0
$ zola serve --interface 0.0.0.0 --port 2000
$ zola serve --interface 0.0.0.0 --base-url 127.0.0.1
$ zola serve --interface 0.0.0.0 --port 2000 --output-dir www/public
2018-11-01 22:36:47 +00:00
$ zola serve --watch-only
2019-07-04 21:42:37 +00:00
$ zola serve --open
2017-09-27 14:37:17 +00:00
```
2019-11-26 19:30:30 +00:00
The serve command will watch all your content and provide live reload without
a hard refresh if possible.
2017-10-03 15:21:18 +00:00
2019-11-26 19:30:30 +00:00
Some changes cannot be handled automatically and thus live reload may not always work. If you
fail to see your change or get an error, try restarting `zola serve` .
2018-03-16 18:11:08 +00:00
2019-11-26 19:30:30 +00:00
You can also point to a config file other than `config.toml` like so (note that the position of the `config` option is important):
2018-03-16 18:11:08 +00:00
```bash
2018-10-18 21:09:32 +00:00
$ zola --config config.staging.toml serve
2018-03-16 18:11:08 +00:00
```
2018-09-22 14:05:07 +00:00
2019-11-26 19:30:30 +00:00
By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
2019-08-24 20:23:08 +00:00
2020-08-12 20:46:07 +00:00
## check
2019-05-27 12:05:07 +00:00
The check subcommand will try to build all pages just like the build command would, but without writing any of the
2019-11-26 19:30:30 +00:00
results to disk. Additionally, it will also check all external links in Markdown files by trying to fetch
them (links in the template files are not checked).
2019-05-27 12:05:07 +00:00
2019-11-26 19:30:30 +00:00
By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
2019-08-24 20:23:08 +00:00
2018-09-22 14:05:07 +00:00
## Colored output
2019-11-26 19:30:30 +00:00
Colored output is used if your terminal supports it.
2018-09-22 14:05:07 +00:00
2019-11-26 19:30:30 +00:00
*Note*: coloring is automatically disabled when the output is redirected to a pipe or a file (i.e., when the standard output is not a TTY).
2018-09-22 14:05:07 +00:00
2019-11-26 19:30:30 +00:00
You can disable this behavior by exporting one of the following two environment variables:
2018-09-22 14:05:07 +00:00
- `NO_COLOR` (the value does not matter)
- `CLICOLOR=0`
2019-11-26 19:30:30 +00:00
To force the use of colors, you can set the following environment variable:
2018-09-22 14:05:07 +00:00
- `CLICOLOR_FORCE=1`