nushell 利用管道控制系统
Summary: Author: 张亚飞 | Read Time: 2 minute read | Published: 2023-02-04
Filed under
—
Categories:
Linux
—
Tags:
Note,
nushell
shell 命令行工具
安装
MacOS
系统通过 brew
安装
brew install nushell
Linux
系统通过 npm
安装在
npm install -g nushell
输入命令 nu
进入 nushell
环境
$ nu
__ ,
.--()°'.' Welcome to Nushell,
'|, . ,' based on the nu language,
!_-(_\ where all data is structured!
Please join our Discord community at https://discord.gg/NtAbbGn
Our GitHub repository is at https://github.com/nushell/nushell
Our Documentation is located at https://nushell.sh
Tweet us at @nu_shell
Learn how to remove this at: https://nushell.sh/book/configuration.html#remove-welcome-message
It's been this long since Nushell's first commit:
4yrs 6months 28days 17hrs 11mins 45secs 833ms 224µs
Startup Time: 73ms 831µs 83ns
~/Server/Run/run_s/shells>
常用用法
文件排序
~/Web/Work/vconsole/config> ls | where type == file | sort-by size | reverse | first 6 | select name size 06/02/2023 04:35:52 PM
╭───┬─────────────────┬────────╮
│ # │ name │ size │
├───┼─────────────────┼────────┤
│ 0 │ common.yaml │ 2.2 KB │
│ 1 │ extra.yaml │ 1.1 KB │
│ 2 │ extra.dev.yaml │ 1.1 KB │
│ 3 │ extra.test.yaml │ 1.1 KB │
│ 4 │ extra.beta.yaml │ 1.1 KB │
│ 5 │ extra.prod.yaml │ 1.1 KB │
╰───┴─────────────────┴────────╯
列出文件大小大于 100M
的文件
$ ls **/* | where size > 100mb
╭────┬──────────────────────────────────────┬──────┬──────────┬────────────╮
│ # │ name │ type │ size │ modified │
├────┼──────────────────────────────────────┼──────┼──────────┼────────────┤
│ 0 │ logs/run-2023-05-25T01-10-29.308.log │ file │ 104.9 MB │ a week ago │
│ 1 │ logs/run-2023-05-25T01-37-29.809.log │ file │ 104.9 MB │ a week ago │
│ 2 │ logs/run-2023-05-25T02-06-34.493.log │ file │ 104.9 MB │ a week ago │
│ 3 │ logs/run-2023-05-25T11-45-31.307.log │ file │ 104.9 MB │ a week ago │
│ 4 │ logs/run-2023-05-26T01-00-02.979.log │ file │ 104.9 MB │ a week ago │
│ 5 │ logs/run-2023-05-29T14-55-42.392.log │ file │ 104.9 MB │ 4 days ago │
│ 6 │ logs/run-2023-05-30T02-00-46.427.log │ file │ 104.9 MB │ 3 days ago │
│ 7 │ logs/run-2023-05-30T08-59-08.837.log │ file │ 104.9 MB │ 3 days ago │
│ 8 │ logs/run-2023-05-30T08-59-13.065.log │ file │ 104.9 MB │ 3 days ago │
│ 9 │ logs/run-2023-05-30T08-59-16.678.log │ file │ 104.9 MB │ 3 days ago │
│ 10 │ logs/run-2023-05-30T08-59-21.207.log │ file │ 104.9 MB │ 3 days ago │
│ 11 │ logs/run-2023-05-30T08-59-24.170.log │ file │ 104.9 MB │ 3 days ago │
│ 12 │ logs/run-2023-05-30T08-59-35.234.log │ file │ 104.9 MB │ 3 days ago │
│ 13 │ logs/test.lll │ file │ 104.9 MB │ a week ago │
│ 14 │ logs/test.log │ file │ 104.9 MB │ a week ago │
│ 15 │ logs/test.o │ file │ 104.9 MB │ a week ago │
│ 16 │ logs/test.ou │ file │ 104.9 MB │ a week ago │
│ 17 │ logs/test.out │ file │ 102.8 MB │ a week ago │
│ 18 │ logs/test.tt │ file │ 104.9 MB │ a week ago │
╰────┴──────────────────────────────────────┴──────┴──────────┴────────────╯
使用help commands
, 友好的 nushell
预先提供了这个”小抄”指令
help commands
过滤
help commands | where name =~ un | select name | to json
使用 get
提取信息,并且通过 ^echo
命令调用外部的命令
sys | get host.sessions.name | each { |it| ^echo $it }
通过 url
获取 api
信息
> http get https://api.github.com/repos/nushell/nushell | get license 06/02/2023 06:01:28 PM
╭─────────┬─────────────────────────────────────╮
│ key │ mit │
│ name │ MIT License │
│ spdx_id │ MIT │
│ url │ https://api.github.com/licenses/mit │
│ node_id │ MDc6TGljZW5zZTEz │
╰─────────┴─────────────────────────────────────╯
循环
ls | enumerate | each { |it| $"Number ($it.index) is size" }
- [Nushell: The only shell you will ever need]()
- nushell
Comments