Tarantool CE/EE Documentation portal logo
Support
Updated at September 7, 2026   01:25 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

os.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---...

os.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...

os.getenv(variable-name)

Get environment variable.

Parameters:

  • variable-name (string) — environment variable name.

Example:

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

os.remove(name)

Remove file or directory.

Parameters:

  • name (string) — name of file or directory which will be removed.

Example:

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

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

Return a formatted date.

Parameters:

  • format-string (string) — instructions
  • time-since-epoch (string) — 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...

os.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$

os.time()

Return the number of seconds since the epoch.

Example:

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

os.clock()

Return the number of CPU seconds since the program start.

Example:

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

os.tmpname()

Return a name for a temporary file.

Example:

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

os.environ()

Return a table containing all environment variables.

Example:

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

os.setenv(variable-name, variable-value)

Set an environment variable.

Parameters:

  • variable-name (string) — environment variable name
  • variable-value (string) — environment variable value

Example:

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

os.setlocale([new-locale-string])

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

Parameters:

  • new-locale-string (string) — new locale.

Example:

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

os.difftime(time1, time2)

Return the number of seconds between two times.

Parameters:

  • time1 (number) — first time value
  • time2 (number) — second time value

Example:

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