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
In a nutshell
  • edit goes down, up goes up one level, up n goes up n levels, top goes to [edit], exit goes back to the previous level.
  • The [edit ...] banner shows your current hierarchy level.
  • top in 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.

[edit]top leveledit protocols ospf[edit protocols ospf]edit area 0[edit protocols ospf area 0]top[edit]

How it works

Moving through the hierarchy

CommandEffect
edit <path>Moves down to that level, creating it in the candidate if needed
upMoves up one level
up <n>Moves up n levels
topJumps to the top [edit] level
exitReturns 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

KeyAction
SpaceCompletes a command keyword
TabCompletes a keyword or a user-defined name, such as a policy or file name
Ctrl+A / Ctrl+EMove to the start or end of the line
Ctrl+B / Ctrl+FMove back or forward one character
Esc+B / Esc+FMove back or forward one word
Ctrl+WDelete the word before the cursor
Ctrl+KDelete from the cursor to the end of the line
Ctrl+UDelete the whole line
Ctrl+P / Ctrl+N or arrowsPrevious 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

HelpWhat it shows
?Possible completions at this point, with a short description
show ?The options for show
help topicUsage guidelines for a configuration topic
help referenceSyntax and description of a configuration statement
help apropos <string>Commands or statements that contain the string
help syslogThe 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 pipeEffect
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
countShows only the number of lines
last <n>Shows the last n lines
no-morePrints everything without the ---(more)--- pause
display setShows configuration as set commands instead of braces
compareIn 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.

show interfaces tersefull outputpipe match geOnly matching linespipe countLine count

At a ---(more)--- prompt, Space shows the next page, Enter shows the next line, and q stops the output.

Exam tip

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.

Watch out

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

  • edit goes down, up goes up one level, up n goes up n levels, top goes to [edit], exit goes back to the previous level.
  • The [edit ...] banner shows your current hierarchy level.
  • top in front of a command runs it from the top without moving.
  • Space completes keywords; Tab also completes user-defined names.
  • ? lists completions; help topic and help reference explain statements.
  • Pipe options: match, except, find, count, last, no-more, display set, compare, save.

Check yourself

  • You typed edit protocols ospf area 0 from [edit]. Where does exit take you?

    Back to [edit], the level you came from. up would 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 example show 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.