User Interfaces · Topic 2 of 4
CLI Navigation, Help and Filtering Output
Learn Junos CLI navigation with edit, up, top and exit, completion keys, the help system and pipe filters such as match for JNCIA-Junos JN0-106.
- 5 min
editgoes down,upgoes up one level,up ngoes up n levels,topgoes to[edit],exitgoes back to the previous level.- The
[edit ...]banner shows your current hierarchy level. topin front of a command runs it from the top without moving.
What it is
The Junos configuration is a hierarchy of statements, like folders inside folders. CLI navigation is moving up and down that hierarchy so that set, delete and show act at the right level.
CLI help is the built-in help: ? for what you can type next, and help commands for explanations. Filtering output uses the pipe | to trim or reformat what a command prints.
How it works
Moving through the hierarchy
| Command | Effect |
|---|---|
edit <path> | Moves down to that level, creating it in the candidate if needed |
up | Moves up one level |
up <n> | Moves up n levels |
top | Jumps to the top [edit] level |
exit | Returns to the level you were at before the last edit |
exit at [edit] | Leaves configuration mode |
up and exit look alike but differ. After edit protocols ospf area 0 from [edit], up takes you to [edit protocols ospf], while exit takes you straight back to [edit], where you came from.
Commands typed at a level are relative to it. At [edit interfaces], set ge-0/0/1 unit 0 family inet address 10.1.1.1/24 is the same as the full command at the top. Add top in front to act from the top without moving, for example top show system host-name or top edit routing-options.
[edit]
user@R1# edit protocols ospf area 0
[edit protocols ospf area 0.0.0.0]
user@R1# set interface ge-0/0/1.0
[edit protocols ospf area 0.0.0.0]
user@R1# up
[edit protocols ospf]
user@R1# top
[edit]
user@R1#
Junos stores area 0 as 0.0.0.0, which is why the banner shows the dotted form. show at a level displays only that part of the candidate.
Completion and editing keys
| Key | Action |
|---|---|
| Space | Completes a command keyword |
| Tab | Completes a keyword or a user-defined name, such as a policy or file name |
| Ctrl+A / Ctrl+E | Move to the start or end of the line |
| Ctrl+B / Ctrl+F | Move back or forward one character |
| Esc+B / Esc+F | Move back or forward one word |
| Ctrl+W | Delete the word before the cursor |
| Ctrl+K | Delete from the cursor to the end of the line |
| Ctrl+U | Delete the whole line |
| Ctrl+P / Ctrl+N or arrows | Previous or next command in history |
The key difference for the exam: Space completes only Junos keywords, while Tab also completes names you created. You can also abbreviate any keyword as long as it stays unique, so sh int ter works for show interfaces terse. show cli history lists your recent commands.
Help
| Help | What it shows |
|---|---|
? | Possible completions at this point, with a short description |
show ? | The options for show |
help topic | Usage guidelines for a configuration topic |
help reference | Syntax and description of a configuration statement |
help apropos <string> | Commands or statements that contain the string |
help syslog | The meaning of a system log message tag |
? works in the middle of a command and keeps what you have already typed. It also lists user-defined items at that point, such as configured interfaces.
Filtering output with the pipe
| Option after the pipe | Effect |
|---|---|
match <text> | Shows only lines that contain the text or regular expression |
except <text> | Hides lines that contain the text |
find <text> | Starts the output at the first line that contains the text |
count | Shows only the number of lines |
last <n> | Shows the last n lines |
no-more | Prints everything without the ---(more)--- pause |
display set | Shows configuration as set commands instead of braces |
compare | In configuration mode, shows changes against the active configuration or a rollback |
save <file> | Saves the output to a file |
Use quotes and | inside them to match several strings, for example show interfaces terse | match "ge-0/0/0|ge-0/0/1". You can chain pipes, such as show log messages | match error | last 10.
At a ---(more)--- prompt, Space shows the next page, Enter shows the next line, and q stops the output.
show configuration | display set is the quickest way to turn a curly-brace configuration into commands you can paste into another device.
Common mistakes
Mixing up up and exit. up always climbs one level. exit returns to where you were before the last edit, which may be several levels higher.
Expecting Space to finish a policy name. Space completes only built-in keywords. Use Tab for names you configured.
Thinking match finds whole words only. match looks for the text anywhere in the line, so match ge-0/0/1 also matches ge-0/0/10. Add more of the string, or use a regular expression, to narrow it.
Running set at the wrong level. A set command is relative to the current level, so check the [edit ...] banner before you type.
show | display set and show configuration | display set print the same statements, but the first shows the candidate and the second shows the active configuration.
What to remember for the exam
editgoes down,upgoes up one level,up ngoes up n levels,topgoes to[edit],exitgoes back to the previous level.- The
[edit ...]banner shows your current hierarchy level. topin front of a command runs it from the top without moving.- Space completes keywords; Tab also completes user-defined names.
?lists completions;help topicandhelp referenceexplain statements.- Pipe options:
match,except,find,count,last,no-more,display set,compare,save.
Check yourself
You typed
edit protocols ospf area 0from[edit]. Where doesexittake you?Back to
[edit], the level you came from.upwould take you to[edit protocols ospf].Which key completes a firewall filter name you created?
Tab. Space completes only built-in keywords.
Which pipe option shows the configuration as set commands?
| display set, for exampleshow configuration | display set.
Topic 2 of 4 in User Interfaces
Test yourself on User Interfaces
The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.