zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

20.3k starsLinux装逼Shell,类sql语法

SQLshell 语法 装逼
2023-06-13 09:17:23 时间

Nushell介绍

一种新的 Shell,Nu 可以在 Linux、macOS 和 Windows 上运行。一次学习,处处可用。

Nu 管道使用结构化数据,你可以用同样的方式安全地选择,过滤和排序。停止解析字符串,开始解决问题。

具备强大的插件系统,Nu可以轻松扩展。使用rust语言开发,目前20.3k stars

GitHub数据

  • 20.3k stars
  • 156 watching
  • 993 forks

开源地址:https://github.com/nushell/nushell

安装

Linux and macOS

> brew install nushell

Windows

> winget install nushell

演示

在 Unix 中,通常在命令之间通过管道将复杂的命令拆分为多个步骤。Nu 在这方面更进了一步,并在很大程度上建立在管道的概念之上。与 Unix 哲学一样,Nu 允许命令输出到标准输出并从标准输入读取。此外,命令可以输出结构化数据(你可以将其视为第三种流)。在管道中工作的命令属于以下三个类别之一

ls | where type == "dir" | table
╭────┬──────────┬──────┬─────────┬───────────────╮
│ #  │   name   │ type │  size   │   modified    │
├────┼──────────┼──────┼─────────┼───────────────┤
│  0 │ .cargo   │ dir  │     0 B │ 9 minutes ago │
│  1 │ assets   │ dir  │     0 B │ 2 weeks ago   │
│  2 │ crates   │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  3 │ docker   │ dir  │     0 B │ 2 weeks ago   │
│  4 │ docs     │ dir  │     0 B │ 2 weeks ago   │
│  5 │ images   │ dir  │     0 B │ 2 weeks ago   │
│  6 │ pkg_mgrs │ dir  │     0 B │ 2 weeks ago   │
│  7 │ samples  │ dir  │     0 B │ 2 weeks ago   │
│  8 │ src      │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  9 │ target   │ dir  │     0 B │ a day ago     │
│ 10 │ tests    │ dir  │ 4.0 KiB │ 2 weeks ago   │
│ 11 │ wix      │ dir  │     0 B │ 2 weeks ago   │
╰────┴──────────┴──────┴─────────┴───────────────╯
  • 产生流的命令(例如,ls
  • 过滤流的命令(例如,where type == "dir"
  • 使用管道输出的命令(例如,table

查找系统中cpu利用率大于3的进程

> ps | where cpu > 3
╭───┬───────┬───────────┬───────┬───────────┬───────────╮
│ # │  pid  │   name    │  cpu  │    mem    │  virtual  │
├───┼───────┼───────────┼───────┼───────────┼───────────┤
│ 0 │  2240 │ Slack.exe │ 16.40 │ 178.3 MiB │ 232.6 MiB │
│ 1 │ 16948 │ Slack.exe │ 16.32 │ 205.0 MiB │ 197.9 MiB │
│ 2 │ 17700 │ nu.exe    │  3.77 │  26.1 MiB │   8.8 MiB │
╰───┴───────┴───────────┴───────┴───────────┴───────────╯

打开文件

Nu 可以将文件和 URL 内容加载为原始文本或结构化数据。例如,你可以将 .toml 文件加载为结构化数据并进行搜索:

> open Cargo.toml
╭──────────────────┬────────────────────╮
│ bin              │ [table 1 row]      │
│ dependencies     │ {record 24 fields} │
│ dev-dependencies │ {record 8 fields}  │
│ features         │ {record 10 fields} │
│ package          │ {record 13 fields} │
│ profile          │ {record 3 fields}  │
│ target           │ {record 2 fields}  │
│ workspace        │ {record 1 field}   │
╰──────────────────┴────────────────────╯

可以根据key一层一层展开打印下级的内容。

> open Cargo.toml | get package
╭───────────────┬────────────────────────────────────╮
│ authors       │ [list 1 item]                      │
│ default-run   │ nu                                 │
│ description   │ A new type of shell                │
│ documentation │ https://www.nushell.sh/book/       │
│ edition       │ 2018                               │
│ exclude       │ [list 1 item]                      │
│ homepage      │ https://www.nushell.sh             │
│ license       │ MIT                                │
│ name          │ nu                                 │
│ readme        │ README.md                          │
│ repository    │ https://github.com/nushell/nushell │
│ rust-version  │ 1.60                               │
│ version       │ 0.63.1                             │
╰───────────────┴────────────────────────────────────╯

更多功能广大网友可以继续挖掘。