Home Explore Blog CI



nushell

2nd chunk of `blog/2021-11-16-nushell_0_40.md`
6f9343672dd32a2adbebf3d949c7829cb32d47d142542eb20000000100001003
 4 │ tmpfs          │ 5120      │ 4         │ 5116      │ 1%   │ /run/lock      │ /run/lock
 5 │ tmpfs          │ 8156408   │ 0         │ 8156408   │ 0%   │ /sys/fs/cgroup │ /sys/fs/cgroup
 6 │ /dev/nvme0n1p1 │ 508932    │ 211684    │ 297248    │ 42%  │ /boot/efi      │ /boot/efi
 7 │ tmpfs          │ 1631280   │ 128       │ 1631152   │ 1%   │ /run/user/1000 │ /run/user/1000
 8 │ /dev/nvme0n1p2 │ 238810780 │ 136867812 │ 89742316  │ 61%  │ /media/st/Data │ /media/st/Data
───┴────────────────┴───────────┴───────────┴───────────┴──────┴────────────────┴────────────────
```

Ahh, that's close to what we want in just one step. Let's go ahead and clean this up a little. First, let's drop that last column. "Mounted on" being two words confused the importer, but all the data is there, we just need to drop the last column.

```
> df | detect columns | drop column
───┬────────────────┬───────────┬───────────┬───────────┬──────┬────────────────
 # │   Filesystem   │ 1K-blocks │   Used    │ Available │ Use% │    Mounted
───┼────────────────┼───────────┼───────────┼───────────┼──────┼────────────────
 0 │ udev           │ 8108824   │ 0         │ 8108824   │ 0%   │ /dev
 1 │ tmpfs          │ 1631284   │ 2068      │ 1629216   │ 1%   │ /run
 2 │ /dev/nvme1n1p2 │ 490691512 │ 346067188 │ 119628844 │ 75%  │ /
 3 │ tmpfs          │ 8156408   │ 251332    │ 7905076   │ 4%   │ /dev/shm
 4 │ tmpfs          │ 5120      │ 4         │ 5116      │ 1%   │ /run/lock
 5 │ tmpfs          │ 8156408   │ 0         │ 8156408   │ 0%   │ /sys/fs/cgroup
 6 │ /dev/nvme0n1p1 │ 508932    │ 211684    │ 297248    │ 42%  │ /boot/efi
 7 │ tmpfs          │ 1631280   │ 128       │ 1631152   │ 1%   │ /run/user/1000
 8 │ /dev/nvme0n1p2 │ 238810780 │ 136867812 │ 89742316  │ 61%  │ /media/st/Data
───┴────────────────┴───────────┴───────────┴───────────┴──────┴────────────────
```

Finally, it'd be nice to be able to have real file sizes for the middle columns, so let's convert the numbers into Nushell's filesize type:

```
> df | detect columns | drop column | into filesize 1K-blocks Used Available
───┬────────────────┬───────────┬──────────┬───────────┬──────┬────────────────
 # │   Filesystem   │ 1K-blocks │   Used   │ Available │ Use% │    Mounted
───┼────────────────┼───────────┼──────────┼───────────┼──────┼────────────────
 0 │ udev           │    8.1 MB │      0 B │    8.1 MB │ 0%   │ /dev
 1 │ tmpfs          │    1.6 MB │   2.1 KB │    1.6 MB │ 1%   │ /run
 2 │ /dev/nvme1n1p2 │  490.7 MB │ 346.1 MB │  119.6 MB │ 75%  │ /
 3 │ tmpfs          │    8.2 MB │ 251.3 KB │    7.9 MB │ 4%   │ /dev/shm
 4 │ tmpfs          │    5.1 KB │      4 B │    5.1 KB │ 1%   │ /run/lock
 5 │ tmpfs          │    8.2 MB │      0 B │    8.2 MB │ 0%   │ /sys/fs/cgroup
 6 │ /dev/nvme0n1p1 │  508.9 KB │ 211.7 KB │  297.2 KB │ 42%  │ /boot/efi

Title: Using 'detect columns' in Nushell to Process 'df' Output
Summary
The 'detect columns' command in Nushell can be used to process the output of commands like 'df'. By piping the output of 'df' to 'detect columns', then using 'drop column' to remove extraneous columns, and finally using 'into filesize' to convert size values to human-readable formats, the data can be easily transformed into a usable Nushell table.