Moving Around and Editing 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
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.
Displaying 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
Filtering 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 commanduser@host>show configuration | ?Possible completions:compare Compare configuration changes with prior versioncount Count occurrencesdisplay Show additional kinds of informationexcept Show only text that does not match a patternfind Search for first occurrence of patternhold Hold text without exiting the --More-- promptlast Display end of output onlymatch Show only text that matches a patternno-more Don't paginate outputrequest Make system-level requestsresolve Resolve IP addressessave Save output text to filetrim Trim specified number of columns from start of linePlacing 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
savecommand after the pipe:user@host>command| savefilenameBy 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 informationcommand in a file:user@host>request support information | savefilenameWrote 1143 lines of output to `filename'user@host>Searching 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
matchcommand after the pipe:user@host>command| matchregular-expressionTo ignore text that matches a regular expression, specify the
exceptcommand after the pipe:user@host>command| exceptregular-expressionIf the
regular-expressioncontains 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
For example, if a command produces the following output:
one twotwo twothree two onefourThe
match twocommand displays:one twotwo twothree two oneThe
except onecommand displays:two twofourList 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 in to the router except for the user "root":
user@host>show system users | except root8:28PM up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00USER TTY FROM LOGIN@ IDLE WHATsheep p0 baa.juniper.net 7:25PM - cliSave the configuration, except for encrypted passwords, to a file:
user@host>show configuration | except SECRET-DATA | save my.output.fileDisplay the output, starting not at the beginning but rather at the first occurrence of text matching a regular expression, using the
findcommand after the pipe:user@host>command| findregular-expressionIf 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.0208.197.169.0/24 *[Static/5] 1d 13:22:11> to 192.168.4.254 via so-3/0/0.0224.0.0.5/32 *[OSPF/10] 1d 13:22:12, metric 1iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160*[Direct/0] 1d 13:22:12> via lo0.0Counting the Number of Lines in the Output
To count the number of lines in the output, specify the
countcommand after the pipe:user@host>command | countuser@host>show configuration | countCount: 269 linesuser@host>show route | countCount: 67 linesDisplaying All Output at Once
To display the output all at once instead of one screen at a time, specify the
no-morecommand after the pipe. This command is equivalent to theset cli screen-length 0command, but affects the output of the one command only.user@host>command| no-moreRetaining 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
holdcommand after the pipe. This feature is useful, for example, when you want to scroll or search through the output.user@host>command | holdFiltering 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| matchregular-expression| exceptregular-expression| matchother-regular-expression| findregular-expression| hold