Home Explore Blog CI



nushell

1st chunk of `cookbook/system.md`
2987ea936fb34f7e2b2c953b9ea1e8cf8ec67f891ed74d4b0000000100000b6f
---
title: System
---

# System

Nu offers many commands that help interface with the filesystem and control your operating system.

### View all files in the current directory

```nu
ls | where type == file
# => ────┬─────────────────────────────────┬──────┬──────────┬────────────────
# =>  #  │              name               │ type │   size   │    modified
# => ────┼─────────────────────────────────┼──────┼──────────┼────────────────
# =>   0 │ CODE_OF_CONDUCT.md              │ file │   3.5 KB │ 10 months ago
# =>   1 │ CONTRIBUTING.md                 │ file │   1.8 KB │ 10 months ago
# =>   2 │ Cargo.lock                      │ file │ 118.4 KB │ 2 hours ago
# =>   3 │ Cargo.toml                      │ file │   4.1 KB │ 2 hours ago
# =>   4 │ Cargo.toml.old                  │ file │   7.2 KB │ 2 weeks ago
# =>   5 │ LICENSE                         │ file │   1.1 KB │ 4 months ago
# =>   6 │ Makefile.toml                   │ file │    473 B │ 10 months ago
# =>   7 │ README.build.txt                │ file │    193 B │ 10 months ago
# =>   8 │ README.md                       │ file │  15.8 KB │ 3 days ago
# =>   9 │ bands.txt                       │ file │    156 B │ 2 hours ago
# =>  10 │ extra_features_cargo_install.sh │ file │     54 B │ 4 months ago
# =>  11 │ files                           │ file │      3 B │ an hour ago
# =>  12 │ payload.json                    │ file │     88 B │ 21 minutes ago
# =>  13 │ rustfmt.toml                    │ file │     16 B │ 10 months ago
# =>  14 │ urls.json                       │ file │    182 B │ 25 minutes ago
# => ────┴─────────────────────────────────┴──────┴──────────┴────────────────
```

---

### View all directories in the current directory

```nu
ls | where type == dir
# => ────┬───────────┬──────┬─────────┬───────────────
# =>  #  │   name    │ type │  size   │   modified
# => ────┼───────────┼──────┼─────────┼───────────────
# =>   0 │ .azureold │ dir  │     0 B │ 3 weeks ago
# =>   1 │ .cargo    │ dir  │     0 B │ 10 months ago
# =>   2 │ .vscode   │ dir  │     0 B │ 10 months ago
# =>   3 │ crates    │ dir  │ 12.3 KB │ 3 weeks ago

Title: System Commands in Nu
Summary
Nu provides a variety of commands designed to interface with the file system and offer control over the operating system. The documentation highlights the use of these commands with practical examples. Specifically, it demonstrates how to view all files in the current directory using the `ls` command combined with a `where` clause to filter by 'file' type. The output is formatted as a table showing file name, type, size, and modification date. Similarly, it shows how to list all directories in the current directory, again using `ls` and `where`, but filtering for 'dir' type. The output table displays the directory name, type, size, and modification date. These commands are crucial for navigating and managing files and directories within the Nu shell environment, providing a more structured and powerful way to interact with the system compared to traditional shells. These examples illustrate basic but essential system operations.