Using the Command-Line Interface
This section contains the following topics:
For more information about the CLI, see the Junos CLI User Guide.
CLI Command Hierarchy
The CLI commands are organized hierarchically, with commands that perform a similar function grouped together under the same level. For example, all commands that display information about the device system and system software are grouped under the show command, and all commands that display information about the routing table are grouped under the show route command. Figure 1 illustrates a portion of the show command hierarchy.
Figure 1: CLI Command Hierarchy Example

To execute a command, you enter the full command name, starting at the top level of the hierarchy. For example, to display a brief view of the routes in the routing table, use the command show route brief.
The hierarchical organization results in commands that have a regular syntax and provides the following features that simplify CLI use:
- Consistent command names—Commands that provide the same type of function have the same name, regardless of the portion of the software they are operating on. For example, all show commands display software information and statistics, and all clear commands erase various types of system information.
- Lists and short descriptions of available commands—Information about available commands is provided at each level of the CLI command hierarchy. If you type a question mark (?) at any level, you see a list of the available commands along with a short description of each command.
- Command completion—Command completion for command names (keywords) and command options is also available at each level of the hierarchy. If you type a partial command name followed immediately by a question mark (with no intervening space), you see a list of commands that match the partial name you typed.
Starting the CLI
To start the CLI:
- Establish a connection with the device:
- To access the device remotely from the network, enter the command you typically use to establish a remote connection (such as Telnet or ssh) using the device hostname.
- To access the device through a management device attached to the console port, start the terminal application.
- To access the device through the J-Web interface, select Troubleshoot>CLI Terminal in the J-Web interface. For more information, see the J-Web Interface User Guide.
- Log in using your username and password.
After you log in, you enter a UNIX shell.
- Start the CLI.% cliuser@host>
The presence of the angle bracket (>) prompt indicates the CLI has started. By default, the prompt is preceded by a string that contains your username and the hostname of the router.
To exit the CLI and return to the UNIX shell, enter the quit command.
CLI Operational Mode
The CLI has two modes: operational and configuration. When you log in to the device and the CLI starts, you are at the top level of operational mode.
To view a list of top-level operational mode commands, type a question mark (?) at the command-line prompt.
user@host> ?Possible completions: clear Clear information in the system configure Manipulate software configuration information file Perform file operations help Provide help information monitor Show real-time debugging information mtrace Trace multicast path from source to receiver ping Ping remote target quit Exit the management session request Make system-level requests restart Restart software process set Set CLI properties, date/time, craft interface message show Show system information ssh Start secure shell on another host start Start shell telnet Telnet to another host test Perform diagnostic debugging traceroute Trace route to remote host
At the top level of operational mode are a number of broad groups of CLI commands that are used to perform the following functions:
- Control the CLI environment.
- Monitor and troubleshoot the device.
- Connect to other systems.
- Manage files and software images.
- Control software processes.
- Stop and reboot the device.
- Enter configuration mode.
To control the CLI environment, see Configuring the CLI Environment. To enter configuration mode, see CLI Configuration Mode. For information about the other CLI operational mode functions, see the Junos OS Administration Guide for Security Devices.
CLI Configuration Mode
To configure the device, including system parameters, routing protocols, security, interfaces, network management, and user access, you must enter configuration mode. In configuration mode, the CLI provides commands to configure the device, load a text (ASCII) file that contains the device configuration, activate a configuration, and save the configuration to a text file.
You enter configuration mode by entering the configure operational mode command. The CLI prompt changes from user@host> to user@host#.
To view a list of configuration mode commands, type a question mark (?) at the command-line prompt. (You do not need to press Enter after typing the question mark.)
user@host# ?Possible completions: Enter Execute this command activate Remove the inactive tag from a statement annotate Annotate the statement with a comment commit Commit current set of changes copy Copy a statement deactivate Add the inactive tag to a statement delete Delete a data element edit Edit a sub-element exit Exit from this level help Provide help information insert Insert a new ordered data element load Load configuration from ASCII file quit Quit from this level rename Rename a statement rollback Roll back to previous committed configuration run Run an operational-mode command save Save configuration to ASCII file set Set a parameter show Show a parameter status Show users currently editing configuration top Exit to top level of configuration up Exit one level of configuration wildcard Wildcard operations
The Junos OS configuration consists of a hierarchy of statements. There are two types of statements: container statements, which contain other statements, and leaf statements, which do not contain other statements. All the container and leaf statements together form the configuration hierarchy.
Each statement consists of a fixed keyword and, optionally, an identifier that you define, such as the name of an interface or a username.
To configure the device or to modify an existing configuration, you add statements to the configuration with the edit and set configuration mode commands. For more information about the CLI configuration editor and configuration mode, see the Junos OS configuration guides.
CLI Basics
This section contains the following topics:
Editing Keystrokes
In the CLI, you use keystrokes to move around on and edit the command line, and to scroll through a list of recently executed commands. Table 3 lists some typical CLI editing tasks and the keystrokes that perform them.
Table 3: CLI Editing Keystrokes
Task Category | Action | Keyboard Sequence |
|---|---|---|
Move the cursor. | Move the cursor back one character. | Ctrl-b |
Move the cursor back one word. | Esc b | |
Move the cursor forward one character. | Ctrl-f | |
Move the cursor forward one word. | Esc f | |
Move the cursor to the end of the command line. | Ctrl-e | |
Delete characters. | Delete the character before the cursor. | Ctrl-h, Delete, or Backspace |
Delete the character at the cursor. | Ctrl-d | |
Delete all characters from the cursor to the end of the command line. | Ctrl-k | |
Delete all characters on the command line. | Ctrl-u or Ctrl-x | |
Delete the word before the cursor. | Ctrl-w or Esc Backspace | |
Delete the word after the cursor. | Esc d | |
Insert recently deleted text. | Insert the most recently deleted text at the cursor. | Ctrl-y |
Redraw the screen. | Redraw the current line. | Ctrl-l |
Display previous command lines. | Scroll backward through the list of recently executed commands. | Ctrl-p |
Scroll forward through the list of recently executed commands. | Ctrl-n | |
Search the CLI history in reverse order for lines matching the search string. | Ctrl-r | |
Search the CLI history by typing some text at the prompt, followed by the keyboard sequence. The CLI attempts to expand the text into the most recent word in the history for which the text is a prefix. | Esc / | |
Repeat keyboard sequences. | Specify the number of times to execute a keyboard sequence. Replace number with a number from 1 through 9, and replace sequence with a keyboard sequence in this table. | Esc number sequence |
Command Completion
You do not always have to remember or type the full command or option name for the CLI to recognize it. To display all possible command or option completions, type the partial command followed immediately by a question mark (?).
To complete a command or option that you have partially typed, press Tab or Spacebar. If the partially typed letters uniquely identify a command, the complete command name appears. Otherwise, a message indicates that your entry is ambiguous or invalid. Possible command completions are displayed if your entry is ambiguous.
You can also use command completion on filenames and usernames. To display all possible values, type one or more characters followed immediately by a question mark. To complete these partial entries, press Tab only. Pressing Spacebar does not work.
Online Help
The CLI provides context-sensitive Help at every level of the command hierarchy. The Help information tells you which commands are available at the current level in the hierarchy and provides a brief description of each.
To get Help while in the CLI, type a question mark (?) in one of the following ways:
- Type a question mark at the command-line prompt. The CLI lists the available commands and options. For examples, see CLI Operational Mode and CLI Configuration Mode.
- Type a question mark after entering the complete name
of a command or command option. The CLI lists the available commands
and options, then redisplays the command names and options that you
typed:
user@host# set schedulers ?regress@arcona# set schedulers ? Possible completions: + apply-groups Groups from which to inherit configuration data + apply-groups-except Don't inherit configuration data from these groups > scheduler Scheduler configuration [edit] user@host# set schedulers
- Type a question mark in the middle of a command name.
The CLI lists possible command completions that match the letters
you have entered so far, then redisplays the letters that you typed.
For example, to list all operational mode commands that start with
the letter s, type the following:
user@host> s?Possible completions: set Set CLI properties, date/time, craft interface message show Show system information ssh Start secure shell on another host start Start shell
When you enter the help commands described in Table 4, the CLI displays usage guidelines and summary information for configuration statements and operational mode commands. You can enter help commands in operational or configuration mode.
Table 4: Help Commands
CLI Command | Description |
|---|---|
help apropos string | Displays Help based on a text string contained in a statement or command name. If the string contains spaces, enclose it in quotation marks. You also can specify a regular expression for the string, using standard UNIX-style regular expression syntax. In configuration mode, this command displays statement names and Help text that match the string specified. In operational mode, this command displays the following types of commands that match the string specified, plus Help text:
For example, to get a list of statements that contain the string traps, enter the help apropos traps command in configuration mode. |
help reference string | Displays summary information for configuration statements. For example, to display summary information for the OSPF hello interval, enter the command help reference ospf hello-interval. Note: In some cases, multiple Help topics are available for the same configuration statement. When an existing Junos OS statement has been modified for Junos OS, two help commands are available—one describing the original Junos OS statement and another describing the updates to that statement for Junos OS. To view the Help topic that describes the modifications made for Junos OS, enter the help command that contains the string junos-es. For example, to view Help for the access profile profile-name authentication-order statement, enter help reference access authentication-order-junos-es. |
help topic string | Displays usage guidelines for configuration statements. For example, to display usage guidelines for the OSPF hello interval, enter the command help topic ospf hello-interval. |
Configuring the CLI Environment
You can configure the CLI environment for your current login session. Your settings are not retained when you exit the CLI.
To display the current CLI settings, enter the show cli command:
user@host> show cliCLI complete-on-space set to on CLI idle-timeout disabled CLI restart-on-upgrade set to on CLI screen-length set to 49 CLI screen-width set to 132 CLI terminal is 'vt100' CLI is operating in enhanced mode CLI working directory is '/cf/var/home/remote'
To change the CLI environment, use the set cli operational mode command:
user@host> set cli ?Possible completions: complete-on-space Set whether typing space completes current word directory Set working directory idle-timeout Set maximum idle time before login session ends prompt Set CLI command prompt string restart-on-upgrade Set whether CLI prompts to restart after software upgrade screen-length Set number of lines on screen screen-width Set number of characters on a line terminal Set terminal type
Table 5 shows how you can change the CLI environment features.
Table 5: Configuring the CLI Environment
Environment Feature | CLI Command | Default Setting | Options |
|---|---|---|---|
Command completion | set cli complete-on-space (on | off) | on—Pressing Tab or Spacebar completes a command. |
|
Your working directory | set cli directory path8 | /cf/var/home/remote | Replace path with the directory you want to enter when you log in to the device. |
Minutes of idle time | set cli idle-time minutes | Your session never times out unless your login class specifies a timeout. |
|
Your session prompt | set cli prompt string | user@host> | Replace string with the prompt you want. If the prompt contains spaces or special characters, enclose string in quotation marks (“ “). |
Restart-after-upgrade prompt | set cli restart-on-upgrade (on | off) | CLI prompts you to restart the device after a software upgrade. |
|
Number of CLI output line displayed at once | set cli screen-length length | Variable (depends on terminal type). |
|
Number of CLI characters displayed on a line | set cli screen-width width | Variable (depends on terminal type). | To change the number of characters displayed on a line, replace width with a value between 0 and 100,000. |
Your terminal type. | set cli terminal terminal-type | unknown, or set by console. | Replace terminal-type with one of the following values:
|
Hide Navigation Pane
Show Navigation Pane
Download
SHA1