fs
read and write files, and manage folders and the current directory
Permissions: files.read, files.write
Files and folders: reading and writing them and moving them around. Every function here reads a path as relative to the current directory unless it starts from the root.
writing
Section titled “writing”ls, rm, cp and the other file functions also work as shell-style commands, like rm -r build, which help(“shell”) explains. In an ordinary call, give the flags by name: rm("build", recursive: true).
Tags: files
readthe contents of one or more files, as text joined into one string, or as bytes with the bytes flagread_filethe contents of one or more files, joined into one stringread_bytesa file’s contents, as bytes, for files that aren’t textwrite_filewrite v to a file, replacing what was thereappend_fileadd v to the end of a file, creating it if neededsave_sessionwrite the session’s variables, functions and units to a file as code that rebuilds themexistswhether a file or directory existsis_dirwhether path is a directory (folder)lswhat’s in a directory, as a table of name, type, size and modifiedduthe biggest files and folders directly in dir, largest first, with each folder counted for everything inside itglobevery path that matches the pattern pat, as a table like ls givesfile_sizea file’s size, as a quantity in bytesmtimewhen a file was last changed, as a datermdelete files and empty directoriesmvmove or rename files and directoriescpcopy filesmkdircreate directories, along with any missing folders above themabspaththe full path from the root of the file system, filling in the current directorycwdthe current directory, which relative paths start frompwdthe current directory, the same as cwd() under the shell’s namecdchange the current directory and return the new one
Functions
Section titled “Functions”read(path: str, *more: str, bytes: bool = false) -> str|bytes
the contents of one or more files, as text joined into one string, or as bytes with the bytes flag
1read("notes.txt").lines.len2read("a.out", bytes: true)[..4] == b"ELF"As a command:
-b,--bytesgive the contents as bytes, for files that aren’t text
read -b a.out# → read("a.out", bytes: true)See also read_file, read_bytes, write_file
read_file
Section titled “read_file”read_file(path: str, *more: str) -> str
the contents of one or more files, joined into one string
Also called cat.
1read_file("notes.txt").lines.len2read_file("data.json").from_json3cat("a.txt", "b.txt")As a command:
cat a.txt b.txt# → cat("a.txt", "b.txt")See also read, write_file, lines, from_csv, grep, wc
read_bytes
Section titled “read_bytes”read_bytes(path: str) -> bytes
a file’s contents, as bytes, for files that aren’t text
1read_bytes("a.out")[..4] == b"\x7fELF"See also read, read_file, bytes, hexdump
write_file
Section titled “write_file”write_file(v: any, path: str) -> nil
write v to a file, replacing what was there
Also called write.
Values are written as text, a list one item per line and a table as CSV, while bytes are written exactly
1[1, 2, 3].write_file("out.txt")2ls().write_file("files.csv")See also read_file, append_file
append_file
Section titled “append_file”append_file(v: any, path: str) -> nil
add v to the end of a file, creating it if needed
A list goes one item per line
1["started {now}"].append_file("log.txt")See also write_file
save_session
Section titled “save_session”save_session(path: str) -> nil
write the session’s variables, functions and units to a file as code that rebuilds them
Run the file later to get them back. A value that can’t be written as code, like a table, is left as a comment
1save_session("defs.zil")See also write_file
exists
Section titled “exists”exists(path: str) -> bool
whether a file or directory exists
1exists("Cargo.toml")See also is_dir
is_dir
Section titled “is_dir”is_dir(path: str) -> bool
whether path is a directory (folder)
1is_dir("src")See also exists
ls(dir: str = “.”, *, all: bool = false, long: bool = false) -> table
what’s in a directory, as a table of name, type, size and modified
1ls()2ls("src").where(|f| f.type == "file").nameAs a command:
-a,--allinclude names starting with a dot, which are hidden otherwise-l,--longaccepted out of habit: the table always has the details
ls -la src# → ls("src", long: true, all: true)du(dir: str = “.”, n: int = 10) -> table
the biggest files and folders directly in dir, largest first, with each folder counted for everything inside it
A table of name, type, size and files, where files is how many files the entry holds. Hidden names are included
1du()2du("src", 3).nameAs a command:
du src 5# → du("src", "5")glob(pat: str) -> table
every path that matches the pattern pat, as a table like ls gives
* matches any part of a name, ? any one character, and ** any number of folders, so **/*.rs finds .rs files at any depth
1glob("**/*.rs").size.sum2glob("*.csv").nameSee also ls
file_size
Section titled “file_size”file_size(path: str) -> quantity
a file’s size, as a quantity in bytes
1file_size("Cargo.lock") to KiBSee also mtime, human_bytes
mtime(path: str) -> date
when a file was last changed, as a date
1now - mtime("Cargo.lock") to hSee also file_size
rm(*paths: str, recursive: bool = false, force: bool = false, dry_run: bool = false) -> table|nil
delete files and empty directories
1rm("out.txt")As a command:
-r,--recursivealso directories and everything in them-f,--forceskip paths that don’t exist instead of failing-n,--dry-runlist what would change, as a table of op, from and to, and change nothing
rm -rf build# → rm("build", recursive: true, force: true)mv(from: str, to: str, *more: str, dry_run: bool = false) -> table|nil
move or rename files and directories
If the last path is a directory, everything before it moves into it, so you can move several at once. Missing folders are created
1mv("draft.txt", "final.txt")As a command:
-n,--dry-runlist what would change, as a table of op, from and to, and change nothing
mv *.log logs# → mv(*glob("*.log").name, "logs")cp(from: str, to: str, *more: str, recursive: bool = false, dry_run: bool = false) -> table|nil
copy files
If the last path is a directory, everything before it is copied into it. Missing folders are created
1cp("data.csv", "backup/data.csv")As a command:
-r,--recursivecopy directories too-n,--dry-runlist what would change, as a table of op, from and to, and change nothing
cp -r src backup# → cp("src", "backup", recursive: true)See also mv
mkdir(path: str, *more: str, parents: bool = false, dry_run: bool = false) -> table|nil
create directories, along with any missing folders above them
1mkdir("out/2026/10")As a command:
-p,--parentsaccepted out of habit: missing folders above are always made-n,--dry-runlist what would change, as a table of op, from and to, and change nothing
mkdir -p out/logs# → mkdir("out/logs", parents: true)See also rm
abspath
Section titled “abspath”abspath(path: str) -> str
the full path from the root of the file system, filling in the current directory
The path doesn’t have to exist
1abspath("src")See also cwd
cwd() -> str
the current directory, which relative paths start from
1cwd()As a command:
cwd# → cwd()pwd() -> str
the current directory, the same as cwd() under the shell’s name
1pwd()As a command:
pwd# → pwd()cd(dir?: str) -> str
change the current directory and return the new one
With no argument, go to your home directory, and with “-”, go back to the previous one
1cd("src")2cd("..")3cd("-")4cd()As a command:
cd ../notes# → cd("../notes")See also cwd
Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.