Module os
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.
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 200 drwxr-xr-x 2 root root 65536 Apr 22 15:49 bin drwxr-xr-x 59 root root 20480 Apr 18 07:58 include drwxr-xr-x 210 root root 65536 Apr 18 07:59 lib drwxr-xr-x 12 root root 4096 Apr 22 15:49 local drwxr-xr-x 2 root root 12288 Jan 31 09:50 sbin --- ...
- shell-command (
-
os.
rename
(old-name, new-name)¶ Rename a file or directory.
Parameters: Example:
tarantool> os.rename('local','foreign') --- - null - 'local: No such file or directory' - 2 ...
-
os.
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 ...
-
os.
remove
(name)¶ Remove file or directory.
Parameters: (string) name = 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: (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 ...
-
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.
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.
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.
Example:
tarantool> os.difftime(os.time() - 0) --- - 1486594859 ...