Interactive shell
About 2267 words
unifi shell opens an interactive console on the controller, in the style of the network operating systems on Cisco and Arista switches. If your hands already know conf t, sh int status and no shut, they work here.
demo/Default> show interfaces "Garage Switch" status
Garage Switch
PORT NAME STATUS VLAN PROFILE SPEED POE CONNECTED TO
1 AP Garden notconnect Default Trunk - auto -
2 Camera Garage connected IoT IoT 100 FE auto 4.4 W Camera Garage
3 Port 3 notconnect Default All - auto -
4 Port 4 notconnect Default All - auto -
5 Wallbox connected IoT IoT 100 FE - Wallbox
6 Garage Door connected IoT IoT 100 FE - Garage Door
7 Old Printer disabled Default All - - -
8 Uplink Core connected Default Trunk 1 GbE - -
demo/Default> configure terminal
● Enter configuration commands, one per line. End with `end` or ctrl+z.
demo/Default(config)# interface "Core Switch" 8
● Commands in this mode change the port immediately; there is nothing to commit.
demo/Default(config-if:Core Switch/Port 8)# description Camera Porch
✓ Core Switch port 8 (Port 8): renamed to "Camera Porch".
demo/Default(config-if:Core Switch/Camera Porch)# poe off
✓ Core Switch port 8 (Camera Porch): PoE off.
demo/Default(config-if:Core Switch/Camera Porch)# end
demo/Default>A short session: ? lists what can follow show, tab completes the command and the device name, interface mode turns PoE off and on again at once, and a VLAN change to a network is staged and then applied with commit.
The shell is a different front end to the same controller, not a different tool: everything it does, the unifi <subject> <verb> commands can do too. Use whichever fits the moment. The shell is at its best for a session of port work, where you'd otherwise repeat the device name on every line.
Start it
unifi shell
unifi --context office --site Warehouse shellThe prompt shows the context and the site, then the mode in parentheses. It ends in > while you're looking and in # once you're in a configuration mode.
Leave with quit, logout or ctrl+d. The shell keeps its command history in the state directory, so ↑ and ctrl+r reach back across sessions.
Type less
Three things make the shell fast, and they're the reason to use it.
Abbreviations. Every keyword can be shortened as long as it stays unambiguous: sh int for show interfaces, conf t for configure terminal. sh always means show; shorten shutdown to shut.
? for help. Type ? at any point of a line and the shell lists what can follow there, with a description for each word and the known names for an argument. It doesn't run anything and doesn't disturb what you've typed. Inside quotes, ? is a plain character.
tab for completion. It completes keywords and names: devices, ports, clients, networks, profiles. Press it again to cycle through several candidates.
Names with blanks work quoted ("Core Switch"), or unquoted when what you typed matches a known name.
Modes
| Mode | Prompt | Enter with | For |
|---|---|---|---|
| Exec | demo/Default> | the shell starts here | looking, and acting on devices and clients |
| Configuration | demo/Default(config)# | configure terminal | choosing what to configure |
| Interface | (config-if:Core Switch/NAS)# | interface <device> <port> | one port |
| Interface range | (config-if-range:Core Switch/20-22)# | interface range <device> <ports> | several ports at once |
| Device | (config-device:Core Switch)# | device <device> | one device |
| Client | (config-client:NAS)# | client <client> | one client |
| Resource | (config-network:IoT)# | network <name>, wifi <name>, resource <kind> <name> | one configuration object |
exit goes up one mode, and from exec mode it leaves the shell. end or ctrl+z returns to exec mode from anywhere. do runs an exec command without leaving a configuration mode, as in do show clients.
Look around
Exec mode is for show commands:
| Command | Shows |
|---|---|
show clients [filter] | connected clients; the filter is an expression such as network == "IoT" |
show devices [device] | the devices, or one in detail |
show interfaces [device] [port] | faceplates and ports; one port in detail |
show interfaces [device] status | the port status table only |
show poe [device] | PoE ports of every switch, or of one, with their mode, state and draw |
show networks, show vlans | networks |
show wifi | WiFi networks |
show port-profiles | port profiles |
show firewall zones, show firewall policies | the zone-based firewall |
show events [count] | the system log, newest first |
show topology | devices and clients as a tree |
show sites | the controller's sites |
show running-config [kind] | the site's configuration as manifests |
show version | controller and CLI versions |
show history | the commands of this session |
Exec mode also acts: reload <device> restarts a device, locate <device> and locate <device> off blink its LED, upgrade <device> installs firmware, and block, unblock and kick deal with a client. site <name> switches the shell to another site of the controller.
Filter the output
Append a filter to any command with |, as on a switch:
demo/Default> show clients vendor == "Sonos" | include Kitchen
Sonos Kitchen 192.168.20.52 02:21:08:01:40:66 2.4GHz IoT AP Hallway Mesh 0 bps 2 kbps
demo/Default> show clients | exclude wired | count
Number of lines: 28
demo/Default> show running-config Network | begin IoT| Filter | Effect |
|---|---|
include <pattern> | keep the lines that match |
exclude <pattern> | drop the lines that match |
begin <pattern> | start at the first line that matches |
count | count the lines |
json | print the data as JSON instead of a table; goes last, also after text filters |
Patterns are regular expressions and ignore case. Filters chain, and their names abbreviate like every keyword: sh cl | i sonos.
Configure ports
Interface mode is where the shell earns its keep.
demo/Default(config)# interface "Core Switch" 8
demo/Default(config-if:Core Switch/Port 8)# show
Core Switch port 8 (Port 8)
Status notconnect
Admin state enabled
Link no link, max 1 GbE, RJ45
Profile All
Native network Default
PoE auto
Connected to -| Command | Effect |
|---|---|
description <text>, name <text> | rename the port |
no description | reset the name to the port number |
poe auto, poe off, poe passthrough, poe 24v | set the PoE mode |
poe cycle | power-cycle the connected device |
shutdown, no shutdown | disable and enable the port |
profile <profile>, switchport profile <profile> | assign a port profile |
switchport access vlan <network> | set the native network, by name or VLAN ID |
show | show the port as it is now |
A range applies every command to all of its ports:
demo/Default(config)# interface range "Core Switch" 20-22
● 3 ports selected; every command applies to all of them.
demo/Default(config-if-range:Core Switch/20-22)# shutdown
✓ Core Switch ports 20-22: shut down.When changes apply
This is the one thing to understand before you change anything, because the shell has two models and the mode decides which one you're in.
Interface, device and client modes apply at once. Every command changes the controller and confirms in one line, like a running-config on a switch. There is nothing to commit and no undo; poe off has turned the power off by the time you see the checkmark. The one stop on the way is the question the plain commands ask too, when a command takes something live offline:
demo/Default(config-if:Core Switch/Camera Driveway)# poe off
Turn PoE off on Core Switch port 10 (Camera Driveway)? What it powers goes dark. [confirm] y
✓ Core Switch port 10 (Camera Driveway): PoE off.enter or y confirms, and anything else cancels with nothing changed. The shell says so when you enter such a mode, and the prompt never shows * there.
Resource modes stage. In network, wifi and resource modes, commands collect changes, and nothing reaches the controller until you commit:
demo/Default(config)# network IoT
● Changes in this mode are staged. `diff` shows them; only `commit` applies them.
demo/Default(config-network:IoT)# vlan 21
● Staged: vlanId = 21 (1 pending, `commit` applies).
demo/Default(config-network:IoT*)# diff
network "IoT"
~ vlanId: 20 → 21
demo/Default(config-network:IoT*)# commit
network "IoT"
~ vlanId: 20 → 21
✓ Network "IoT" updated.The prompt shows * after the object's name while changes are staged.
| Command | Effect |
|---|---|
set <path> <value> | stage a value for a field; paths are the ones unifi <subject> get <name> --output yaml shows |
unset <path> | stage the removal of a field |
enable, disable | stage enabling or disabling the object |
vlan <id> | networks only: stage the VLAN ID |
show | show the object as staged |
diff | show what is staged |
commit | apply the staged changes |
abort | discard them and leave the mode |
Only commit applies. Leaving a resource mode by any other means, exit, end, quit, ctrl+d or abort, discards what is staged and says so. Nothing is ever applied because you left.
Entering a resource mode with a name that doesn't exist starts a new object: network Lab followed by vlan 50 and commit creates the network. no network <name>, no wifi <name> and no resource <kind> <name> delete, after a confirmation.
Disruptive commands ask first.reload, upgrade, shutdown and the no ... deletions print a question; enter or y proceeds, anything else cancels.
Secrets read <redacted> in everything the shell prints, and a line that sets one goes into the history with its value redacted.
Scripts
With --command, or with commands on standard input, the shell runs them as a script and exits:
unifi shell -c "show interfaces 'Core Switch' status"
unifi shell -c "conf t" -c "interface 'Core Switch' NAS" -c "poe off"
unifi shell < changes.txtA script is one command per line, the way you'd paste a configuration into a switch. Lines that start with ! or # are comments.
! changes.txt: move the porch camera to the IoT profile, and the IoT network to VLAN 21
configure terminal
interface "Core Switch" 8
description Camera Porch
switchport profile IoT
poe auto
exit
network IoT
vlan 21
commit
endA script stops at the first line that fails, names the line with its cause, and exits with code 1. Interface-mode lines before it have already been applied; there's no transaction across the script.
$ printf 'show version\nbogus\nshow sites\n' | unifi shell --no-banner
UniFi Network 10.0.160
unifi-cli 0.1.0
Context demo
Site Default
✗ The word "bogus" at column 1 is not understood here.
Line 2 of standard input failed (`bogus`).
Advice:
• Type `?` to list what can be entered here.
• The script stopped at this line. Nothing was changed.
Caused by:
→ % Invalid input detected at '^' marker.Two rules keep scripts from doing things by accident.
A script that leaves a resource mode with staged changes fails, because the shell can't know whether you forgot commit or meant to discard:
$ unifi shell -c "conf t" -c "network IoT" -c "vlan 21" -c "end"
✗ The script leaves the network "IoT" without applying its 1 staged change.
Line 4 of --command failed (`end`).
Advice:
• Add a `commit` line before the script leaves the mode.
• Add `abort` instead if the changes are not wanted.
• The script stopped at this line. Nothing was changed.And the shell asks in the same situations as the plain commands: when something live goes offline or is destroyed. Blocking a client that is connected, shutting down a port that has a link, turning PoE off on a port that powers something and the no ... deletions all ask; shutting down an unused port doesn't. A script can't answer, so such a line fails unless --yes is given, which answers every question of the script with yes:
$ unifi shell -c "conf t" -c "interface 'Core Switch' 'Camera Driveway'" -c "poe off"
✗ The command needs confirmation (Turn PoE off on Core Switch port 10 (Camera Driveway)? What it powers goes
dark.), and a script cannot answer.
Line 3 of --command failed (`poe off`).
Advice:
• Pass `--yes` to confirm every question of the script.
• The script stopped at this line. Nothing was changed.
$ unifi shell --yes -c "conf t" -c "interface 'Core Switch' 'Camera Driveway'" -c "poe off"
✓ Core Switch port 10 (Camera Driveway): PoE off.For scripts, the plain commands are usually the better tool. unifi ports set prints JSON and has stable flags; shell scripts shine when you already have the change as a list of switch-style lines.
The shell prints text, and it has no output redirection. A line with > or >> is refused with a pointer to the alternatives; redirect the whole command from your system shell instead, as in unifi shell -c "show clients" > clients.txt. --output json and --output yaml are rejected for it; end a show command that lists objects with | json instead, also after text filters: show clients vendor == "Sonos" | include Kitchen | json.
Editing keys
| Key | Action |
|---|---|
| ↑ ↓, ctrl+p ctrl+n | history |
| ctrl+r | search the history |
| ctrl+a ctrl+e | start and end of the line |
| alt+b alt+f | back and forward one word |
| ctrl+w | delete the word before the cursor |
| ctrl+u ctrl+k | delete to the start or end of the line |
ctrl+l, or the command clear | clear the screen |
| ctrl+c | cancel the line |
| ctrl+z | return to exec mode |
| ctrl+d | leave the shell |
Type help inside the shell for a summary of all of this.
