[Contents] [Prev] [Next] [Index] [Report an Error]


Move Around and Edit the Command Line

In the CLI, you can use keyboard sequences to move around on a command line and edit the command line. You can also use keyboard sequences to scroll through a list of recently executed commands. Table 2 lists the CLI keyboard sequences. They are the same as those used in Emacs.


Table 2: CLI Keyboard Sequences

Category
Action
Keyboard Sequence
Move the Cursor
Move the cursor back one character.
Ctrl-b
Move the cursor back one word.
Esc-b or Alt-b
Move the cursor forward one character.
Ctrl-f
Move the cursor forward one word.
Esc-f or Alt-f
Move the cursor to the beginning of the command line.
Ctrl-a
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, Esc-Backspace, or Alt-Backspace
Delete the word after the cursor.
Esc-d or Alt-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. number can be from 1 through 9.
Esc-number sequence or Alt-number sequence

How Output Appears on the Screen

When you issue commands in operational mode CLI, the output appears on the screen. If the output is longer than the screen, you can display it one screen at a time using a UNIX more-type interface.

You can also redirect the output through a UNIX-type pipe, either to apply simple filters to the output or to redirect the output to a file.

Display Output One Screen at a Time

If the output is longer than the screen, the ---More--- prompt indicates that more output is available. Table 3 describes how you can scroll at the ---More--- prompt. As soon as the CLI calculates how long the output is (usually by the second screen), the percentage of the command output already displayed appears next to the prompt.


Table 3: ---More--- Prompt Keyboard Sequences

Objective
Result
Keyboard Sequence
Get Help
Display help information about the keyboard sequences you can display at the ---More--- prompt.
h
Scroll Down
Scroll down one line.
Enter, Return, k, Ctrl-m, Ctrl-n, or down arrow
Scroll down one-half screen.
Tab, d, Ctrl-d, or Ctrl-x
Scroll down one whole screen.
Space or Ctrl-f
Scroll down to the bottom of the output.
Ctrl-e or G
Display the output all at once instead of one screen at a time. (Same as specifying the | no-more command after a pipe.)
N
Scroll Up
Display the previous line of output.
j, Ctrl-h, Ctrl-p, or up arrow
Scroll up one-half screen.
u or Ctrl-u
Scroll up one whole screen.
b or Ctrl-b
Scroll up to the top of the output.
Ctrl-a or g
Search
Search forward for a string.
/string
Search backward for a string.
?string
Repeat the previous search for a string.
n
Search for a text string. You are prompted for the string to match. (Same as specifying the | match string command.)
m or M
Search, ignoring a text string. You are prompted for the string to not match. (Same as specifying the | except string command.)
e or E
Interrupt or End Output, Redraw the Output, and Save the Output to a File
Interrupt the display of output.
Ctrl-C, q, Q, or Ctrl-k
Do not redisplay the CLI prompt immediately after displaying the output, but remain at the ---More--- prompt. (Same as specifying the | hold command.)
H
Clear any match conditions and display the complete output.
c or C
Redraw the output on the screen.
Ctrl-l
Save the command output to a file. You are prompted for a filename. (Same as specifying the | save filename command.)
s or S

Filter Command Output

You can redirect the output of operational mode commands into a file or into filters. When you display help about these commands, one of the options listed is |, which is a pipe to redirect the output. For example:

user@host> show configuration ?
Possible completions:
    <[Enter]>                Execute this command
    |                Pipe through a command

user@host> show configuration | ? 
Possible completions:
    count                Count occurrences
    except                Show only text that does not match a pattern
    find                Search for the first occurrence of a pattern
    hold                Hold text without exiting the ---More--- prompt
    match                Show only text that matches a pattern
    no-more                Don't paginate output
    resolve                Resolve IP addresses
    save                Save output text to a file
    trim                Trim specified number of columns from the start line

Place Command Output in a File

When the output is very long, when you need to store or analyze the output, or when you need to send the output in e-mail, you can redirect the output to a file. Doing this is useful when the output scrolls off the screen, making it difficult to cut the output from a window and paste it into another.

To save the output to a file, specify the save command after the pipe:

user@host> command | save filename 

By default, the file is placed in your home directory on the router. For information about how you can specify the filename, see How to Specify Filenames and URLs.

This example stores the output of the request support information command in a file:

user@host> request support information | save filename 
Wrote 1143 lines of output to `filename'
user@host>

Search for a String in the Output

You can filter the output to search for a text matching a regular expression. You can match a regular expression, match everything except a regular expression, or find the first occurrence of text matching a regular expression. All searches are not case-sensitive.

To match a regular expression, specify the match command after the pipe:

user@host> command | match regular-expression 

To ignore text that matches a regular expression, specify the except command after the pipe:

user@host> command | except regular-expression 

If the regular-expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks.

You use extended regular expressions to specify what text in the output to match. Command regular expressions implement the extended (modern) regular expressions as defined in POSIX 1003.2. Table 4 lists common regular expression operators.


Table 4: Common Regular Expression Operators

Operator
Match...
|
One of the two terms on either side of the pipe.
^
At the beginning of an expression, used to denote where the command begins, where there might be some ambiguity.
$
Character at the end of a command. Used to denote a command that must be matched exactly up to that point. For example, allow-commands "show interfaces $" means that the user cannot issue show interfaces detail or show interfaces extensive.
[ ]
Range of letters or digits. To separate the start and end of a range, use a hyphen ( - ).
( )
A group of commands, indicating an expression to be evaluated and the result is then evaluated as part of the overall expression.

For example, if a command produces the following output:

one two
two two
three two one
four

The match two command displays:

one two
two two
three two one

The except one command displays:

two two
four

List all the ATM interfaces in the configuration:

user@host> show configuration | match at- 
    at-2/1/0 {
    at-2/1/1 {
    at-2/2/0 {
    at-5/2/0 {
    at-5/3/0 {

Display a skeleton of your router configuration:

[edit]
user@host # show | match {
system {
    root-authentication {
    name-server {
    login {
        class superuser {
        user junipero {
            authentication {
    services {
    syslog {
        file messages {
    processes {
chassis {
    alarm {
        sonet {
    images {
        scb {
        fpc {
interfaces {
    at-2/1/1 {
        atm-options {
        unit 0 {
    at-2/2/0 {
    ...
snmp {
    community public {
        clients {
routing-options {
    static {
        route 0.0.0.0/0 {
        route 192.168.0.0/16 {
        route 208.197.169.0/24 {
protocols {
    rsvp {
        interface so-5/1/0 {
    mpls {
        interface so-5/1/0 {
    bgp {
        group internal {
    ospf {
        area 0.0.0.0 {
            interface so-5/1/0 {

List all users who are logged into the router except for the user "root":

user@host> show system users | except root
 8:28PM  up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00
USER     TTY FROM              LOGIN@  IDLE WHAT
sheep    p0  baa.juniper.net   7:25PM     - cli

Save the configuration, except for encrypted passwords, to a file:

user@host> show configuration | except SECRET-DATA | save my.output.file 

Display the output, starting not at the beginning but rather at the first occurrence of text matching a regular expression, using the find command after the pipe:

user@host> command | find regular-expression 

If the regular expression contains spaces, operators, or wildcard characters, enclose the expression in quotation marks.

List the routes in the routing table starting at 208.197.169.0:

user@host> show route | find 208.197.169.0
208.197.169.0/24   *[Static/5] 1d 13:22:11
                    > to 192.168.4.254 via so-3/0/0.0
224.0.0.5/32       *[OSPF/10] 1d 13:22:12, metric 1

iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160
                   *[Direct/0] 1d 13:22:12
                    > via lo0.0

Count the Number of Lines in the Output

To count the number of lines in the output, specify the count command after the pipe:

user@host> command | count 

For example:

user@host> show configuration | count
Count: 269 lines
user@host> show route | count
Count: 67 lines

Display All Output at Once

To display the output all at once instead of one screen at a time, specify the no-more command after the pipe. This command is equivalent to the set cli screen-length 0 command, but affects the output of the one command only.

user@host> command | no-more 

Retain the Output after the Last Screen

When you view output one screen at a time, you typically return to the CLI prompt after viewing the last screen.

To not return immediately, use the hold command after the pipe. This feature is useful, for example, when you want to scroll or search through the output.

user@host> command | hold 

Filter Command Output Multiple Times

For the output of a single command, you can redirect the output one or more times. For example:

user@host> command | match regular-expression | except regular-expression | 
match other-regular-expression | find regular-expression | hold 

[Contents] [Prev] [Next] [Index] [Report an Error]