Return to index

os functions

bool = can_read(string)

top

Check if path is readable.

Example:

# Example for can_read
println can_read("/etc/passwd")
println can_read("/nonexistent/file")


bool = can_write(string)

top

Check if path is writeable.

Example:

# Example for can_write
println can_write("/tmp")


bool = cd(string)

top

Changes directory to a given path.

Example:

# Example for cd
println cd("/tmp")


bool = chmod(path,mode_string)

top

Change file permissions. Mode string is octal (e.g. "755").

Example:

# Example for chmod
touch("/tmp/za_chmod.txt")
chmod("/tmp/za_chmod.txt", "644")


bool = chown(path,user[,group])

top

Change file owner and group. User and group can be names or numeric IDs.

Example:

# Example for chown
try
    println chown("/tmp", "root", "root")
catch err
    println "Chown failed"
endtry


chroot(string)

top

Performs a chroot to a given path.

Example:

# Example for chroot
try
    println chroot("/tmp")
catch err
    println "Chroot failed"
endtry


bool = copy(src_string,dest_string)

top

Copy a single file.

Example:

# Example for copy
write_file("/tmp/test.txt", "hello")
println copy("/tmp/test.txt", "/tmp/test2.txt")


string = cwd()

top

Returns the current working directory.

Example:

# Example for cwd
println cwd()


bool = delete(string)

top

Delete a file.

Example:

# Example for delete
write_file("/tmp/test.txt", "hello")
println delete("/tmp/test.txt")


[]structs|[]string = dir([filepath[,filter[,options_map]])

top

Returns an array containing file information on path filepath.


filter can be specified, as a regex, to narrow results.


options_map supports: .depth(int), .names(bool), .exclude(str), .absolute(bool).


Each array element contains name,path,depth,mode,size,mtime and is_dir fields.


These specify filename, full path, recursion depth, file mode, file size, modification time and directory status respectively.

Example:

# Example for dir
dir()  # usage


string = env()

top

Return all available environmental variables.

Example:

# Example for env
println env()


string = get_env(key_name)

top

Return the value of the environmental variable key_name.

Example:

# Example for get_env
println get_env("HOME")
println get_env("PATH")
println get_env("NONEXISTENT_VAR")


[]string = glob(pattern[,base_dir])

top

Returns an array of file paths matching a glob pattern.


pattern specifies the glob pattern (supports *, ?, []).


base_dir optionally specifies the base directory to search in (defaults to current directory).


Returns full paths to all matching files and directories.

Example:

# Example for glob
glob("hello")  # usage


bool = group_add(groupname[,options])

top

Add a system group. Options: gid (auto-allocated if not provided).

Example:

# Example for group_add
try
    group_add("testgroup")
catch err
    println "Group add failed"
endtry


bool = group_del(groupname)

top

Remove a system group.

Example:

# Example for group_del
try
    group_del("testgroup")
catch err
    println "Group del failed"
endtry


struct = group_info(groupname)

top

Get detailed information about a group.

Example:

# Example for group_info
try
    println group_info("root")
catch err
    println "Group info failed"
endtry


[]struct = group_list()

top

List all system groups with details (gid, members).

Example:

# Example for group_list
println group_list()


bool = group_membership(username,groupname,action)

top

Manage group membership. Action: add, remove.

Example:

# Example for group_membership
try
    println group_membership("root")
catch err
    println "Group membership failed"
endtry


string = groupname(int)

top

Lookup a group name by group id.

Example:

# Example for groupname
println groupname(3.14)


bool = is_device(mode_number)

top

Checks if a file mode indicates a device.

Example:

# Example for is_device
mode = file_mode("/dev/null")
println is_device(mode)
println is_device(file_mode("/tmp"))


bool = is_pipe(mode_number)

top

Checks if a file mode indicates a named pipe.

Example:

# Example for is_pipe
mode = file_mode("/tmp")
println is_pipe(mode)


bool = is_setgid(mode_number)

top

Checks if a file mode indicates a setgid file.

Example:

# Example for is_setgid
mode = file_mode("/etc/passwd")
println is_setgid(mode)


bool = is_setuid(mode_number)

top

Checks if a file mode indicates a setuid file.

Example:

# Example for is_setuid
mode = file_mode("/etc/passwd")
println is_setuid(mode)


bool = is_socket(mode_number)

top

Checks if a file mode indicates a socket.

Example:

# Example for is_socket
mode = file_mode("/tmp")
println is_socket(mode)


bool = is_sticky(mode_number)

top

Checks if a file mode indicates a sticky file.

Example:

# Example for is_sticky
println is_sticky(42)


bool = is_symlink(mode_number)

top

Checks if a file mode indicates a symbolic link.

Example:

# Example for is_symlink
println is_symlink(42)


bool = mkdir(path[,mode_string|options_map])

top

Create a directory. Mode string is octal (e.g. "755"). Options map: .recursive (bool), .mode (string).

Example:

# Example for mkdir
mkdir("/tmp/za_mkdir_test")
if is_dir("/tmp/za_mkdir_test")
    delete("/tmp/za_mkdir_test")
endif


bool = mkdir_p(path[,mode_string])

top

Create a directory and all parent directories. Mode string is octal (e.g. "755").

Example:

# Example for mkdir_p
mkdir_p("/tmp/test_mkdir_p")  # usage


string = parent(string)

top

Returns the parent directory.

Example:

# Example for parent
println parent("/home/user/documents/file.txt")


string = readlink(path)

top

Return the target of a symbolic link, or empty string if not a symlink.

Example:

# Example for readlink
println readlink("/etc/localtime")


bool = rename(src_string,dest_string)

top

Rename a file.

Example:

# Example for rename
write_file("/tmp/old.txt", "hello")
println rename("/tmp/old.txt", "/tmp/new.txt")


set_env(key_name,value_string)

top

Set the value of the environmental variable key_name.

Example:

# Example for set_env
set_env("ZA_TEST", "hello")


bool = symlink(src_path,dst_path)

top

Create a symbolic link.

Example:

# Example for symlink
try
    println symlink("/etc/passwd", "/tmp/za_symlink_example")
catch err
    println "symlink failed"
endtry


bool = sync()

top

Flush all filesystem buffers to disk.

Example:

# Example for sync
println sync()


string = temp_dir([pattern])

top

Create a temporary directory and return its path.

Example:

# Example for temp_dir
d = temp_dir("za-example-")
println d
write_file(d + "/test.txt", "hello")
println read_file(d + "/test.txt")


string = temp_file([pattern])

top

Create a temporary file and return its path.

Example:

# Example for temp_file
f = temp_file("za-example-")
println f
write_file(f, "hello world")
println read_file(f)


bool = touch(path)

top

Create an empty file if it does not exist, or update its modification time if it does.

Example:

# Example for touch
f = temp_file("za-touch-")
println touch(f)


bool = truncate(path,size)

top

Truncate a file to the specified size.

Example:

# Example for truncate
f = temp_file("za-truncate-")
write_file(f, "hello world")
println truncate(f, 5)


int = umask(int)

top

Sets the umask value. Returns the previous value. umask() without args just returns the current value.

Example:

# Example for umask
println umask(022)


bool = user_add(username[,options])

top

Add a system user. Options: uid, gid, home, shell, groups, create_home.

Example:

# Example for user_add
try
    user_add("testuser", "password")
catch err
    println "User add failed"
endtry


bool = user_del(username[,options])

top

Remove a system user. Options: remove_home.

Example:

# Example for user_del
try
    user_del("testuser")
catch err
    println "User del failed"
endtry


struct = user_info(username)

top

Get detailed information about a user.

Example:

# Example for user_info
try
    println user_info("root")
catch err
    println "User info failed"
endtry


[]struct = user_list()

top

List all system users with details (uid, gid, home, shell).

Example:

# Example for user_list
println user_list()


string = username(int)

top

Lookup a username by user id.

Example:

# Example for username
println username(3.14)