on efdeba3 help sign in
urbit.org/using/filesystem.udon
460 lines 13 kB history raw
1:- :~ navhome/'/docs/'
2 navuptwo/'true'
3 next/'true'
4 sort/'4'
5 title/'Introduction to the Filesystem'
6 ==
7;>
9# Introduction to the Filesystem
12Urbit has its own revision-controlled filesystem, Clay. Clay is a typed, global,
13referentially transparent namespace. An easy way to think about it is like typed
14`git` with continuous sync.
16The most common way to use Clay is to mount a Clay node in a Unix directory. The
17Urbit process will watch this directory and automatically record edits as
18changes, Dropbox style. The mounted directory is always at the root of your
19pier directory.
21## Quickstart
23This quick-start guide will walk you through some common commands. Follow along
24using your Dojo. When you get a `>=` message after entering a command, the means
25that the command was successful.
27When developing it's a good idea to use a separate desk. Create a `%sandbox`
28desk based on the `%home` desk:
30```
31|merge %sandbox ~your-urbit %home
32```
34Running `our` produces your ship-name, meaning that you can run the following
35command instead of typing out the entire thing. Useful for comets, due to their
36very long names.
38```
39|merge %sandbox our %home
40```
42Most of the time we want to use Clay from Unix. Mount the entire contents of
43your `sandbox` desk to Unix:
45```
46~your-urbit:dojo> |mount /=sandbox=
47```
49To explore the filesystem from inside Urbit `+ls` and `+cat` are useful. `+ls`
50displays files in the current directory, and `+cat` displays the contents of
51a file.
53We can use `%` to mean "current directory." The result of the command below
54is just like using `ls` in a Unix terminal.
56```
57~your-urbit:dojo> +ls %
58```
60Notice how `+cat %` does the same thing. That's because everything in Clay,
61including directories, is a file.
63Let's explore the `/web` directory of the `%sandbox` desk.
65```
66~your-urbit:dojo> +ls /=sandbox=/web
67```
69Let's see the contents of `/=sandbox=/web/md`:
71```
72~your-urbit:dojo> +cat /=sandbox=/web/md
73```
75Now let's navigate to that folder using `=dir`, which is a like `cd` in Unix.
77```
78~your-urbit:dojo> =dir /=sandbox=/web/md
79```
81Youl'll notice that your prompt is now `~your-urbit:dojo/sandbox/web/md>`. To
82change back to our home directory, we use `=dir` without any path.
84```
85~your-urbit:dojo/sandbox/web/md> =dir
86```
88Sync from your friend `~some-ship`'s `%experiment` desk to your
89`%sandbox` desk:
91```
92|sync %sandbox ~some-ship %experiment
93```
95If and when your sync is successful, you will receive a message:
97```
98activated sync from %experiment on ~some-ship to %sandbox
99```
101The ship that you sync from will get their own message indicating that you're
102both connected as peers:
104```
105; ~your-urbit is your neighbor.
106```
108---
110## Manual
112### Paths
114A path in Clay is a list of URL-safe text, restricted to the characters
115`[a z]`,`[0 9]`, `.`, `-`, `_`, and `~`. Formally this is a `(list knot)`,
116meaning that each segment, delineated by `/`, is of the `knot` ASCII-text type.
117In other words, paths are expressed as `/foo/bar/baz`. File extensions are
118separated from file names with `/`, not `.`. Extensions are syntactically
119identical to subdirectories, except that they must terminate the path.
121Paths begin with a piece of data called a `beak`. A beak is formally a
122`(p=ship q=desk r=case)`; it has three components, and might look like
123`/~dozbud-namsep/home/11`.
125The first `beak` component is `ship`, which is, as you might guess, the name of
126an Urbit ship. The second component is `desk`, which is a workspace meant to
127contain other directories; the default desk is `%home`. The third component is
128`case`, which represents version information in various ways: date and time;
129a version sequence, which is a value incremented by one whenever a file on the
130given `desk` is modified; or an arbitrary plaintext label.
132You can find what your `beak` is at any given moment by
133typing `%` in the Dojo and looking at the first three results.
135We use `beak`s because, unlike the current internet, the Urbit network uses a
136global namespace. That means that a file named `example.hoon` in the `/gen`
137directory on the `%home` desk of your ship `~lodleb-ritrul` would have a
138universal address to anyone else on the network:
139`~lodleb-ritrul/home/186/gen/example.hoon`. That, of
140course, doesn't mean that everyone on the network has privileges to access that
141path.
143The structure that combines a `beak` with further path information is called a
144`beam`.
146##### Relative paths
148The `%` command, which we gestured at in the above section, represents the
149*relative path*, which is the path where you are currently working. If your
150working directory is just your home desk, indicated by the
151prompt `~your-planet:dojo>`, then running the command below will print your
152working directory's `beam` information: your `beak`, and a `~` that represents
153the empty list since no path is present.
155```
156~your-urbit:dojo> %
157```
159`%`s can be stacked to indicate one level further up in the hierarchy for each
160additional `%`. Try the following command:
162```
163~your-planet:dojo> %%%
164```
166You'll probably notice that it only has your ship name and the empty list. The
167two additional `%`s abandoned the `case` and the `desk` information by moving
168up twice the hierarchy.
170There are no local relative paths. `/foo/bar` must be written as
171`%/foo/bar`.
173##### Substitution
175You don't need to write out the explicit path every time you want to reference
176somewhere outside of your working directory. You can substitute `=` for the
177segments of a path.
179Recall that a full address in the the Urbit namespace is a `beam`: the
180`/ship/desk/case/path`. If you've switched to another desk before, you're
181already familiar with substitution syntax:
183```
184~your-urbit:dojo> =dir /=sandbox=
185```
187The above command substitutes uses substitution to use your current `ship` and
188`case`; only the `desk` argument, which is located between the other two, is
189given something new. Without substitution, you would need to write:
191```
192~your-urbit:dojo> =dir /~your-urbit/home/85
193```
195Substitutions work the same way in `beak`s (the `ship/desk/case` part) and
196paths. For example, if you are in the `/gen` directory, you can reference a file
197in the `/app` directory like below. (`+cat` displays the contents of a file).
199```
200~your-urbit:dojo/home/gen> +cat /===/app/curl/hoon
201```
203Note what was substituted out, and note that we don't need to separate `=` with
204`/`.
206If we changed our working directory to something called `/gen/gmail`, we could
207access a file called
209```
210~fasdul-balsev-lodleb-ritrul:dojo/home/gen/gmail> +cat /===/app/=/split/hoon
211```
213Because both paths share a directory named `/gmail` at the same position in the
214address hierarchy -- which, if you recall, is just a `list` -- the above command
215works!
217We can do the same thing between desks. If `%sandbox` has been merged with
218`%home`, the following command will produce the same results as the above
219command.
221```
222~your-urbit:dojo/home/gen/gmail> +cat /=sandbox=/app/=/split/hoon
223```
225Most commonly this is used to avoid having to know the current revision
226number in the `dojo`: `~lodleb-ritrul/home/~2018.10.2..00.35.44..d7e8/gen/example.hoon`
228##### Changing directories
230Change the working directory with `=dir`. It's our equivalent of the Unix `cd`.
232For example, the syntax to navigate to `/home/gen/ask` is:
234```
235~your-urbit:dojo> =dir /=gen=/ask
236```
238This command will turn your prompt into something like this:
240```
241~your-urbit:dojo/gen/ask>
242```
244Using `=dir` without anything else uses the null path, which returns you to
245your home desk.
247```
248~your-urbit:dojo> =dir
249```
251To go up levels in the path hierarchy, recall the relative path expression
252`%`. Stacking them represents another level higher in the hierarchy than
253the current working directory for each `%` beyond the initial. The command below
254brings you one level up:
256```
257~your-urbit:dojo/gen> =dir %%
258```
260### Revision-control
262##### Mount
264Syntax: `|mount /clay/path [Unix-name]`
266Mount the `clay-path` at the Unix mount point `Unix-name`.
268*Examples:*
270```
271|mount %/web
272```
274Mounts `%/web` to `/web` inside your pier directory.
276```
277|mount %/gen generators
278```
280Mounts `%/gen` to `/generators` inside your pier directory.
282##### Unmount
284```
285|unmount [clay-path || Unix-name]
286```
288Unmount the path or name from Unix.
290*Examples:*
292```
293|unmount %/web
294```
296Unmounts the path `%/web` from whatever name it was mounted as.
298```
299|unmount %generators
300```
302Unmounts the Unix path `/generators`.
304```
305|merge desk beak[, =gem strategy]
306```
308Merges a `beak` into a `desk` using an optional merge `strategy`.
310A `beak` is a ship-desk-case triple, encoded as a
311path(`/~dozbud/home/2`)
313*Examples:*
315```
316|merge %home-work /=home=, =gem %fine
317```
319Merge `/=home=` into `%home-work` using merge strategy `%fine`.
321```
322|merge %examples ~wacbex-ribmex %examples
323```
325Merge the `%examples` desk from `~waxbex-ribmex`
327```
328|sync desk plot [plot-desk]
329```
331Subscribe to continuous updates from remote `plot` on local `desk`.
332`plot-desk` can specify the remote `desk` name. When omitted it is
333defaulted to being the same as `desk`. Non-comet urbits have
334`|sync %home ~parent %kids` automatically set up (where `~parent` is the
335planet that issued a moon, the star that issued a planet, or the galaxy
336that issued a star).
338*Examples:*
340```
341|sync %home-local ~dozbud %home
343|sync %home ~doznec
344```
346```
347|unsync desk plot [plot-desk]
348```
350Unsubscribe from updates from remote `plot` on local `desk` with
351optional `plot-desk`. Arguments must match original `|sync` command.
353Example:
355```
356|unsync %home-local ~dozbud %home
357```
359```
360|label desk name`
361```
363Label the current version of `desk` `name`.
365Example:
367```
368|label %home release
369```
371### Merge strategies
373`%init` - Used if it's the first commit to a desk. Also can be used to
374"reinitialize" a desk -- revision numbers keep going up, but the new
375revision isn't necessarily a descendent of the previously numbered
376version, allowing merges to be rerun.
378`%this` - Keep what's in Bob's desk, but join the ancestry.
380`%that` - take what's in Alice's desk, but join the ancestry. This is
381the reverse of `%this`. This is different from `%init` because the new
382commit has both sides in its ancestry.
384`%fine` - "fast-forward" merge. This succeeds if and only if one head is in the
385ancestry of the other.
387`%meet`, `%mate`, and `%meld` - find the most recent common ancestor to
388use as our merge base.
390A `%meet` merge only succeeds if the changes from the merge base to
391Alice's head (hereafter, "Alice's changes") are in different files than
392Bob's changes. In this case, the parents are both Alice's and Bob's
393heads, and the data is the merge base plus Alice's changed files plus
394Bob's changed files.
396A `%mate` merge attempts to merge changes to the same file when both
397Alice and Bob change it. If the merge is clean, we use it; otherwise, we
398fail. A merge between different types of changes -- for example,
399deleting a file vs changing it -- is always a conflict. If we succeed,
400the parents are both Alice's and Bob's heads, and the data is the merge
401base plus Alice's changed files plus Bob's changed files plus the merged
402files.
404A `%meld` merge will succeed even if there are conflicts. If there are
405conflicts in a file, then we use the merge base's version of that file,
406and we produce a set of files with conflicts. The parents are both
407Alice's and Bob's heads, and the data is the merge base plus Alice's
408changed files plus Bob's changed files plus the successfully merged
409files plus the merge base's version of the conflicting files.
411`%auto` - meta-strategy. Check to see if Bob's desk exists, and if it
412doesn't we use an `%init` merge. Otherwise, we progressively try
413`%fine`, `%meet`, and `%mate` until one succeeds. If none succeed, we
414merge Bob's desk into a scratch desk. Then, we merge Alice's desk into
415the scratch desk with the `%meld` option to force the merge. Finally, we
416annotate any conflicts, if we know how.
418### Manipulation
420##### +cat
422Syntax: `+cat path [path ...]`
424Similar to Unix `cat`. `+cat` takes one or more `path`s, and prints their
425contents. If that `path` is a file, the contents of the file is printed. If the
426`path` terminates in a directory, the list of names at that path is produced.
428##### +ls
430Syntax: `+ls path`
432Similar to Unix `ls`. `+ls` takes a single `path`.
434Produces a list of names at the `path`.
436```
437~your-urbit:dojo> +cat %/our/home/gen/curl/hoon
438```
440##### |rm
442Syntax: `|rm path`
444Remove the data at `path`. `path` must be a path to actual node, not a
445'directory'
447##### |cp
449Syntax: `|cp to from`
451Copy the file at `from` into the path `to`.
453##### |mv
455Syntax: `|mv to from`
457Move the file at `from` into the path `to`.
459In Clay, `|mv` is just a shorthand for `|cp` then `|rm`. The `|rm`
460doesn't happen unless the `|cp` succeeds.