Moving around your system
As we’ve seen in other chapters, ls is a command for viewing the contents of a path. Nu will return the contents as a table that we can use.
The command also takes an optional argument, to change what you’d like to view. For example, we can list the files that end in “.md”
───┬────────────────────┬──────┬─────────┬────────────
# │ name │ type │ size │ modified
───┼────────────────────┼──────┼─────────┼────────────
0 │ CODE_OF_CONDUCT.md │ File │ 3.4 KB │ 5 days ago
1 │ CONTRIBUTING.md │ File │ 886 B │ 5 days ago
3 │ TODO.md │ File │ 1.6 KB │ 5 days ago
───┴────────────────────┴──────┴─────────┴────────────
The asterisk (*) in the above optional argument “*.md” is sometimes called a wildcard or a glob. It lets us match anything. You could read the glob “*.md” as “match any filename, so long as it ends with ‘.md’ “
Nu also uses modern globs as well, which allow you access to deeper directories.
ls **/*.md
────┬───────────────────────────────────────────┬──────┬─────────┬────────────
────┼───────────────────────────────────────────┼──────┼─────────┼────────────
0 │ .github/ISSUE_TEMPLATE/bug_report.md │ File │ 592 B │ 5 days ago
1 │ .github/ISSUE_TEMPLATE/feature_request.md │ File │ 595 B │ 5 days ago
2 │ CODE_OF_CONDUCT.md │ File │ 3.4 KB │ 5 days ago
4 │ README.md │ File │ 15.0 KB │ 5 days ago
5 │ TODO.md │ File │ 1.6 KB │ 5 days ago
6 │ crates/nu-source/README.md │ File │ 1.7 KB │ 5 days ago
7 │ docker/packaging/README.md │ File │ 1.5 KB │ 5 days ago
8 │ docs/commands/README.md │ File │ 929 B │ 5 days ago
10 │ docs/commands/append.md │ File │ 1.4 KB │ 5 days ago
To change from the current directory to a new one, we use the cd
command. Just as in other shells, we can use either the name of the directory, or if we want to go up a directory we can use the ..
shortcut.
Changing the current working directory can also be done if cd
is omitted and a path by itself is given:
> ./new_directory
Note: changing the directory with cd
changes the PWD
environment variable. This means that a change of a directory is kept to the current block. Once you exit the block, you’ll return to the previous directory. You can learn more about working with this in the environment chapter.
Nu also provides some basic filesystem commands that work cross-platform.
> mv item location
We can copy an item from one location to another:
We can remove an item:
The three commands also can use the glob capabilities we saw earlier with .
Finally, we can create a new directory using the command:
> mkdir new_directory