# Command line options

The command line for invoking KDB-X has the form:


q [[file](#file)] [-option [parameters] … ]

**Options**
 [-b blocked](#-b-blocked)                    [-q quiet mode](#-q-quiet-mode)
 [-c console size](#-c-console-size)               [-r replicate](#-r-replicate)
 [-C HTTP size](#-c-http-size)                  [-s secondary threads](#-s-secondary-threads)
 [-e error traps](#-e-error-traps)                [-S random seed](#-s-random-seed)
 [-E TLS Server Mode](#-e-tls-server-mode)            [-t timer ticks](#-t-timer-ticks)
 [-g garbage collection](#-g-garbage-collection)         [-T timeout](#-t-timeout)
 [-l log updates](#-l-log-updates)                [-u disable syscmds](#-u-disable-syscmds)
 [-L log sync](#-l-log-sync)                   [-u usr-pwd local](#-u-usr-pwd-local)
 [-o UTC offset](#-o-utc-offset)                 [-U usr-pwd](#-u-usr-pwd)
 [-p listening port](#-p-listening-port)             [-w workspace](#-w-workspace)
 [-P display precision](#-p-display-precision)          [-W start week](#-w-start-week)
                               [-z date format](#-z-date-format)


[`.z.x`](dotz.md#zx-argv) (argv),
[`.z.X`](dotz.md#zx-raw-command-line) (raw command line)

## file

This is either the script to load (\*.q, \*.k, \*.s), or a file or a directory.
```bash
$ q sp.q
KDB-X 5.0.20251113 2025.11.13 Copyright (C) 1993-2025 Kx Systems
...
```
```q
+`p`city!(`p$`p1`p2`p3`p4`p5`p6`p1`p2;`london`london`london`london`london`lon..
(`s#+(,`color)!,`s#`blue`green`red)!+(,`qty)!,900 1000 1200
+`s`p`qty!(`s$`s1`s1`s1`s2`s3`s4;`p$`p1`p4`p6`p2`p2`p4;300 200 100 400 200 300)
q)
```

> **Warning — Operating systems may create hidden files, such as `.DS_Store`, that block loading of a directory.**
>
>
## `-b` (blocked)
```syntax
-b
```

Block write-access to a KDB-X database, for any handle context ([`.z.w`](dotz.md#zw-handle)) other than 0.
Blocks [`hdel`](hdel.md) keyword (since V4.1t 2021.10.13, V4.0 2023.08.11).
Blocks hopen of a file (since 4.1t 2021.10.13, 4.0 2023.08.11)
```bash
~/q$ q -b
```
```q
q)aa:([]bb:til 4)
q)\p 5001
q)
```

and in another task
```q
q)h:hopen 5001
q)h"count aa"
4
q)h"aa:10#aa"
'noupdate
q)
```

Use [`\_`](syscmds.md#_-hide-q-code) to check if client write-access is blocked:
```q
~/q$ q -b
..
q)\_
1
```

## `-c` (console size)
```syntax
-c r c
```

Set console maximum rows and columns, default 25 80.

[`\c` system command](syscmds.md#c-console-size) for detail

## `-C` (HTTP size)
```syntax
-C r c
```

Set HTTP display maximum rows and columns.

[`\C` system command](syscmds.md#c-http-size) for detail

## `-e` (error traps)
```syntax
-e [0|1|2]
```

Sets error-trapping mode.
The default is 0 (off).

[`\e` system command](syscmds.md#e-error-trap-clients) for detail

## `-E` (TLS Server Mode)
```syntax
-E 0        / plain
-E 1        / plain & TLS
-E 2        / TLS only
```

Since V3.4.

[`\E` system command](syscmds.md#e-tls-server-mode)


[SSL/TLS](../how_to/io_and_communication/ssl.md#basic-tls-setup)

## `-g` (garbage collection)
```syntax
-g 0        / deferred (default)
-g 1        / immediate
```

Sets garbage-collection mode.

[`\g` system command](syscmds.md#g-garbage-collection-mode) for detail

## `-l` (log updates)
```syntax
-l
```

Log updates to filesystem.

[Logging](../how_to/manage_streaming_data/logging.md)

## `-L` (log sync)
```syntax
-L
```

As [`-l`](#-l-log-updates), but sync logging.

[Logging](../how_to/manage_streaming_data/logging.md)

## `-o` (UTC offset)
```syntax
-o N
```

Sets local time offset as `N` hours from UTC, or minutes if `abs[N]>23`
(Affects [`.z.Z`](dotz.md#zz-local-datetime))

[`\o` system command](syscmds.md#o-offset-from-utc) for detail

## `-p` (listening port)

_Set listening port_
```syntax
-p [rp,][hostname:](portnumber|servicename)
```

See

[Listening port](../how_to/io_and_communication/listening-port.md) for detail.

[`hopen`](hopen.md)


[`\p` system command](syscmds.md#p-listening-port)


[Multithreaded input mode](../how_to/io_and_communication/listening-port.md#multi-threaded-input-mode),
[Changes in 3.5](https://code.kx.com/q/releases/ChangesIn3.5/#socket-sharding)


[Load balancing](../how_to/io_and_communication/listening-port.md#load-balancing)

## `-P` (display precision)
```syntax
-P N
```

Display precision for floating-point numbers, i.e. the number of digits shown.

[`\P` system command](syscmds.md#p-precision) for detail

## `-q` (quiet mode)
```syntax
-q
```

Quiet, i.e. no startup banner text or session prompts. Typically used where no console is required.
```bash
~/q$ q
KDB-X 5.0.20251113 2025.11.13 Copyright (C) 1993-2025 Kx Systems
...
```
```q
q)2+2
4
q)
```

and with `-q`
```bash
~/q$ q -q
```
```q
2+2
4
```

[`.z.q`](dotz.md#zq-quiet-mode) (quiet mode)

## `-r` (replicate)
```syntax
-r :host:port[:user[:password]]
```

Replicate from `:host:port`.

[`\r` system command](syscmds.md#r-replication-primary)

## `-s` (secondary threads)
```syntax
-s N
```

Number of secondary threads or processes available for parallel processing.

[`\s` system command](syscmds.md#s-number-of-secondary-threads) for detail

## `-S` (random seed)
```syntax
-S N
```

Sets `N` as value of random seed.

[`\S` system command](syscmds.md#s-random-seed) for detail


[Roll, Deal](deal.md#seed)

## `-t` (timer ticks)
```syntax
-t N
```

Period in milliseconds between timer ticks. Default is 0, for no timer.

[`\t` system command](syscmds.md#t-timer) for detail

## `-T` (timeout)
```syntax
-T N
```

Timeout in seconds for client queries, i.e. maximum time a client call will execute. Default is 0, for no timeout.

[`\T` system command](syscmds.md#t-timeout) for detail

## `-u` (disable syscmds)

## `-u` (usr-pwd local)

## `-U` (usr-pwd)
```syntax
-u 1        / blocks system functions and file access
-U file     / sets password file, blocks \x
-u file     / both the above
```

`-u 1` disables

- system commands from a remote (signals `'access`), including exit via `"\\"`
- access to files outside the current directory for any handle context ([`.z.w`](dotz.md#zw-handle)) other than 0. Segmented database partitions using directories outside the current working directory can be enabled using the method described [here](../how_to/interact_with_databases/segment.md#using-symlinks).
- hopen on a fifo (since 4.1t 2021.10.13, 4.0 2023.08.11)
- hopen of a file (since 4.1t 2021.10.13, 4.0 2023.08.11)
- the [`exit`](exit.md) keyword (since 4.1t 2021.07.12)
- the [`hdel`](hdel.md) keyword (since V4.1t 2021.10.13, V4.0 2023.08.11)

??? danger "Only a simple protection against “wrong” queries"

    For example, setting a system command in `.z.ts` and starting the timer still works. The right system command could for example expose a terminal, so the user running the database could be fully impersonated and compromised from then on.

`-U file`

- sets a password file
- disables [`\x`](syscmds.md#x-expunge) (even on the local console)

The password file is a text file with one credential on each line.
(No trailing blank line/s.)
```txt
user1:password1
user2:password2
```

The password can be

- plain text
- an MD5 hash of the password
- an SHA-1 hash of the password (since V4.0 2020.03.17)
```q
q)raze string md5 "this is my password"
"210d53992dff432ec1b1a9698af9da16"
q)raze string -33!"mypassword" / -33! calculates sha1
"91dfd9ddb4198affc5c194cd8ce6d338fde470e2"
```

Internal function [`-33!`](internal.md#-33x-sha-1-hash)

`-u file` combines the above, i.e. `-u file` is equivalent to `-u 1 -U file`.

## `-w` (workspace)
```syntax
-w N
```

Workspace limit in MB for the heap across threads.
Default is 0: no limit.

[`\w` system command](syscmds.md#w-workspace) for detail


[`.Q.w`](dotq.md#w-memory-stats)

> **Detail — Before V4.0 2020.03.17 this command set the limit for the heap per thread.**
>
>
> **Tip — Other ways to limit resources**
>
>
> On Linux systems, administrators might prefer [cgroups](https://en.wikipedia.org/wiki/Cgroups) as a way of limiting resources.
>
> On Unix systems, memory usage can be constrained using `ulimit`, e.g. 
>
> ```bash
> ulimit -v 262144
> ```
>
> limits virtual address space to 256MB.
>
## `-W` (start week)
```syntax
-W N
```

Set the start-of-week offset, where 0 is Saturday. The default is 2, i.e Monday.

[`\W` system command](syscmds.md#w-week-offset) for detail

## `-z` (date format)
```syntax
-z [0|1]
```

Set the format for `"D"$` date parsing.

[`\z` system command](syscmds.md#z-date-parsing) for details.

[![](https://code.kx.com/q/img/xkcd.tar.png)](https://xkcd.com/1168/)
_xkcd.com_
