Save["filename",symbol]
appends definitions associated with the specified symbol to a file.
Save["filename","patt"]
appends definitions associated with all symbols whose names match the string pattern "patt".
Save["filename","context`"]
appends definitions associated with all symbols in the specified context.
Save["filename",{object1,object2,…}]
appends definitions associated with several objects.
Save
Save["filename",symbol]
appends definitions associated with the specified symbol to a file.
Save["filename","patt"]
appends definitions associated with all symbols whose names match the string pattern "patt".
Save["filename","context`"]
appends definitions associated with all symbols in the specified context.
Save["filename",{object1,object2,…}]
appends definitions associated with several objects.
Details and Options
- Save uses FullDefinition to include subsidiary definitions.
- Save writes out definitions in InputForm.
- Save uses Names to find symbols whose names match a given string pattern.
- You can use Save["filename","s"] to write out the definition for the value of a symbol s itself.
- Save works with local and cloud objects.
- Save[File["filename"],…] is also supported.
- The following options can be given:
-
ExcludedContexts Automatic contexts excluded from recursive inclusion IncludedContexts All contexts considered for recursive inclusion
Examples
open all close allBasic Examples (2)
tempfile = FileNameJoin[{$TemporaryDirectory, "saved.wl"}]a = "This must be saved";Save the value of the variable in a file:
Save[tempfile, a]Loading the file restores the value of a:
Clear[a]Get[tempfile];aDeleteFile[tempfile]Create multiple definitions to save:
a = 5;
f[x_] := x ^ 2Save the definitions to standard out to see how they would be written to a file:
Save["stdout", {a, f}]Scope (3)
Save a definition into a file specified by the File object:
tempfile = File@FileNameJoin[{$TemporaryDirectory, "saved.wl"}]a = "Some string";Save[tempfile, a]Clear[a]Get[tempfile]DeleteFile[tempfile]Local objects can be used with Save to save definitions persistently:
a = 5;
f[x_] := x ^ 2Save[LocalObject["definitions"], {a, f}]Cloud objects can be used with Save to save definitions in the cloud:
a = 5;
f[x_] := x ^ 2Save[CloudObject["definitions"], {a, f}]Options (2)
ExcludedContexts (1)
By default, certain system-internal contexts are excluded from recursive inclusions:
x := $TimeZoneWithCleanup[f = CreateFile[],
Save[f, x];FilePrint[f],
DeleteFile[f]]Use ExcludedContexts{} to save definitions of all non-protected symbols:
WithCleanup[f = CreateFile[],
Save[f, x, ExcludedContexts -> {}];FilePrint[f],
DeleteFile[f]]IncludedContexts (1)
Limit recursive inclusion of symbols to the contexts "c1`" and "c2`" only:
x := {c1`bar, c1`Private`bar , c2`baz}
c1`bar := 5
c1`Private`bar := 1
c2`baz := 3WithCleanup[f = CreateFile[],
Save[f, x, IncludedContexts -> {"c1`", "c2`"}];FilePrint[f],
DeleteFile[f]]Applications (1)
Properties & Relations (3)
Save writes the output of FullDefinition to a file:
g[x_] := x ^ 3SetAttributes[f, Listable];
f[x_] := g[x ^ 2]Save["stdout", f]Saved definitions can be read into the Wolfram Language using Get:
f[x_] := x ^ 2file = Close[OpenWrite[]]Save[file, f]Print the contents of the saved file:
FilePrint[file]Clear definitions in the current session:
ClearAll[f];
Definition[f]Get the definitions into the current session:
Get[file]Definition[f]By default, definitions attached to "System`" symbols are not pulled in:
x := Subscript[y, 1]
Subscript[y, 1] := 17
WithCleanup[f = CreateFile[],
Save[f, x];FilePrint[f],
DeleteFile[f]]Use ExcludedContexts{} to pull in definitions from all contexts:
WithCleanup[f = CreateFile[],
Save[f, x, ExcludedContexts -> {}];FilePrint[f],
DeleteFile[f]]Alternatively, attach definitions to your own symbols:
Clear[Subscript]
y/:Subscript[y, 1] = 17
WithCleanup[f = CreateFile[],
Save[f, x];FilePrint[f],
DeleteFile[f]]Tech Notes
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 2016 (11.0) ▪ 2021 (12.3)
Text
Wolfram Research (1988), Save, Wolfram Language function, https://reference.wolfram.com/language/ref/Save.html (updated 2021).
CMS
Wolfram Language. 1988. "Save." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/Save.html.
APA
Wolfram Language. (1988). Save. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Save.html
BibTeX
@misc{reference.wolfram_2026_save, author="Wolfram Research", title="{Save}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/Save.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_save, organization={Wolfram Research}, title={Save}, year={2021}, url={https://reference.wolfram.com/language/ref/Save.html}, note=[Accessed: 12-June-2026]}