Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

Module os

Overview

The os module contains the functions execute(), rename(), getenv(), remove(), date(), exit(), time(), clock(), tmpname(), environ(), setenv(), setlocale(), difftime(). Most of these functions are described in the Lua manual Chapter 22 The Operating System Library.

Index

Below is a list of all os functions.

Name

Use

os.execute()

Execute by passing to the shell

os.rename()

Rename a file or directory

os.getenv()

Get an environment variable

os.remove()

Remove a file or directory

os.date()

Get a formatted date

os.exit()

Exit the program

os.time()

Get the number of seconds since the epoch

os.clock()

Get the number of CPU seconds since the program start

os.tmpname()

Get the name of a temporary file

os.environ()

Get a table with all environment variables

os.setenv()

Set an environment variable

os.setlocale()

Change the locale

os.difftime()

Get the number of seconds between two times

execute(shell-command)

Execute by passing to the shell.

Parameters:

  • shell-command (string) — what to execute.

Example:

tarantool> os.execute('ls -l /usr')total 200drwxr-xr-x   2 root root 65536 Apr 22 15:49 bindrwxr-xr-x  59 root root 20480 Apr 18 07:58 includedrwxr-xr-x 210 root root 65536 Apr 18 07:59 libdrwxr-xr-x  12 root root  4096 Apr 22 15:49 localdrwxr-xr-x   2 root root 12288 Jan 31 09:50 sbin---...
Example

rename(old-name, new-name)

Rename a file or directory.

Parameters:

  • old-name (string) — name of existing file or directory,

  • new-name (string) — changed name of file or directory.

Example:

tarantool> os.rename('local','foreign')---- null- 'local: No such file or directory'- 2...
Example

getenv(variable-name)

Get environment variable.

Parameters: (string) variable-name = environment variable name.

Example:

tarantool> os.getenv('PATH')---- /usr/local/sbin:/usr/local/bin:/usr/sbin...
Example

remove(name)

Remove file or directory.

Parameters: (string) name = name of file or directory which will be removed.

Example:

tarantool> os.remove('file')---- true...
Example

date(format-string[, time-since-epoch])

Return a formatted date.

Parameters: (string) format-string = instructions; (string) time-since-epoch = number of seconds since 1970-01-01. If time-since-epoch is omitted, it is assumed to be the current time.

Example:

tarantool> os.date("%A %B %d")---- Sunday April 24...
Example

exit()

Exit the program. If this is done on a server instance, then the instance stops.

Example:

tarantool> os.exit()user@user-shell:~/tarantool_sandbox$
Example

time()

Return the number of seconds since the epoch.

Example:

tarantool> os.time()---- 1461516945...
Example

clock()

Return the number of CPU seconds since the program start.

Example:

tarantool> os.clock()---- 0.05...
Example

tmpname()

Return a name for a temporary file.

Example:

tarantool> os.tmpname()---- /tmp/lua_7SW1m2...
Example

environ()

Return a table containing all environment variables.

Example:

tarantool> os.environ()['TERM']..os.environ()['SHELL']---- xterm/bin/bash...
Example

setenv(variable-name, variable-value)

Set an environment variable.

Example:

tarantool> os.setenv('VERSION','99')----...
Example

setlocale([new-locale-string])

Change the locale. If new-locale-string is not specified, return the current locale.

Example:

tarantool> string.sub(os.setlocale(),1,20)---- LC_CTYPE=en_US.UTF-8...
Example

difftime(time1, time2)

Return the number of seconds between two times.

Example:

tarantool> os.difftime(os.time() - 0)---- 1486594859...
Example