Cisco Nexus 7000 Series NX-OS Fundamentals Configuration Guide, Release 4.0
Understanding the CLI
Downloads: This chapterpdf (PDF - 381.0KB) The complete bookPDF (PDF - 3.29MB) | Feedback

Understanding the CLI

Table Of Contents

Understanding the CLI

Information About the CLI Prompt

Command Modes

About Command Modes

EXEC Command Mode

Global Configuration Command Mode

Interface Configuration Command Mode

Subinterface Configuration Command Mode

Exiting a Configuration Command Mode

Command Mode Summary

Special Characters

Keystroke Shortcuts

Abbreviating Commands

Identifying Your Location in the Command Hierarchy

Using the no Form of a Command

Configuring CLI Variables

About CLI Variables

Configuring CLI Variables

Command Aliases

About Command Aliases

Defining Command Aliases

Command Scripts

Running a Command Script

Echoing Information to the Terminal

Delaying Command Action

Context-Sensitive Help

Understanding Regular Expressions

Special Characters

Single-Character Patterns

Multiple-Character Patterns

Anchoring

Searching and Filtering show Command Output

Filtering and Searching Keywords

grep and egrep Utilities

less Utility

sed Utility

Searching and Filtering from the --More-- Prompt

BIOS Loader> Prompt

Examples Using the CLI

Defining Command Aliases

Using CLI Session Variables

Using the System-Defined Timestamp Variable

Running a Command Script

Additional References

Related Documents


Understanding the CLI


This chapter describes the Cisco NX-OS software CLI.

This chapter includes the following sections:

Information About the CLI Prompt

Command Modes

Special Characters

Keystroke Shortcuts

Abbreviating Commands

Identifying Your Location in the Command Hierarchy

Using the no Form of a Command

Configuring CLI Variables

Command Scripts

Context-Sensitive Help

Understanding Regular Expressions

Searching and Filtering show Command Output

BIOS Loader> Prompt

Examples Using the CLI

Additional References

Information About the CLI Prompt

Once you have successfully accessed the device, the CLI prompt displays in the terminal window of your console port or remote workstation (see Example 3-1).

Example 3-1 Initial CLI Prompt

User Access Verification
login: admin
Password:<password>
Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Copyright (c) 2002-2008, Cisco Systems, Inc. All rights reserved.
The copyrights to certain works contained in this software are owned by other third 
parties and used and distributed under license. Certain components of this software are 
licensed under the GNU General Public License (GPL) version 2.0 or the GNU Lesser General 
Public License (LGPL) Version 2.1. A copy of each such license is available at
http://www.opensource.org/licenses/gpl-2.0.php and
http://www.opensource.org/licenses/lgpl-2.1.php
switch# 

You can change the default device hostname (see the "Changing the Device Hostname" section on page 5-5).

From the CLI prompt, you can do the following:

Use CLI commands for configuring features

Access the command history

Use command parsing functions

Command Modes

This section includes the following topics:

About Command Modes

EXEC Command Mode

Global Configuration Command Mode

Interface Configuration Command Mode

Subinterface Configuration Command Mode

Exiting a Configuration Command Mode

Command Mode Summary

About Command Modes

The Cisco NX-OS CLI is divided into command modes, which define the actions available to the user. Command modes are "nested" and must be accessed in sequence. As you navigate from one command mode to another, an increasingly larger set of commands become available. All commands in a higher command mode are accessible from lower command modes. For example, the show commands are available from any configuration command mode. Figure 3-1 shows how command access builds from EXEC mode to global configuration mode.

Figure 3-1 Command Modes

EXEC Command Mode

When you first log in, the Cisco NX-OS software places you in EXEC mode. The commands available in EXEC mode include the show commands that display device status and configuration information, the clear commands, and other commands that perform actions that you do not save in the device configuration.

Global Configuration Command Mode

Global configuration mode provides access to the broadest range of commands. The term "global" indicates characteristics or features that affect the device as a whole. You can enter commands in global configuration mode to configure your device globally, or to enter more specific configuration modes to configure specific elements such as interfaces or protocols.

To access the global configuration mode, follow this step:

 
Command
Purpose

Step 1 

configure terminal


Example:

switch# configure terminal

switch(config)#

Enters global configuration mode.

Note The CLI prompt changes to indicate that you are in global configuration mode.

Interface Configuration Command Mode

One example of a specific configuration mode that you enter from global configuration mode is interface configuration mode. To configure interfaces on your device, you must specify the interface and enter interface configuration mode.

You must enable many features on a per-interface basis. Interface configuration commands modify the operation of the interfaces on the device, such as Ethernet interfaces or management interfaces (mgmt 0).

For more information about configuring interfaces, see the Cisco Nexus 7000 Series NX-OS Interfaces Configuration Guide, Release 4.0.

For more information about interface commands, see the Cisco Nexus 7000 Series NX-OS Interfaces Command Reference, Release 4.0.

SUMMARY STEPS

1. configure terminal

2. interface type number

DETAILED STEPS

 
Command
Purpose

Step 1 

configure terminal


Example:

switch# configure terminal

switch(config)#

Enters global configuration mode.

Step 2 

interface type number


Example:

switch(config)# interface ethernet 2/2

switch(config-if)#

Specifies the interface you that want to configure.

The CLI places you into interface configuration mode for the specified interface

Note The CLI prompt changes to indicate that you are in interface configuration mode.

Subinterface Configuration Command Mode

From global configuration mode, you can access a configuration submode for configuring VLAN interfaces called subinterfaces. In subinterface configuration mode, you can configure multiple virtual interfaces on a single physical interface. Subinterfaces appear to a protocol as distinct physical interfaces.

Subinterfaces also allow multiple encapsulations for a protocol on a single interface. For example, you can configure IEEE 802.1Q encapsulation to associate a subinterface with a VLAN.

For more information about configuring subinterfaces, see the Cisco Nexus 7000 Series NX-OS Interfaces Configuration Guide, Release 4.0.

For more information about subinterface commands, see the Cisco Nexus 7000 Series NX-OS Interfaces Command Reference, Release 4.0.

SUMMARY STEPS

1. configure terminal

2. interface type number.subint

DETAILED STEPS

 
Command
Purpose

Step 1 

configure terminal


Example:

switch# configure terminal

switch(config)#

Enters global configuration mode.

Step 2 

interface type number.subint


Example:

switch(config)# interface ethernet 2/2.1

switch(config-subif)#

Specifies the VLAN interface to be configured.

The CLI places you into a subinterface configuration mode for the specified VLAN interface.

Note The CLI prompt changes to indicate that you are in global configuration mode.

Exiting a Configuration Command Mode

To exit from any configuration command mode, perform one of the following tasks:

Command
Purpose

exit


Example:

switch(config-if)# exit

switch(config)#


Exits from the current configuration command mode and return to the previous configuration command mode.

end


Example:

switch(config)# end

switch#

Exits from the configuration command mode and returns to EXEC mode.

Ctrl-z


Example:

switch(config)# ^z

switch#


Exits the current configuration command mode and returns to EXEC mode.


Caution If you use Ctrl-Z at the end of a command line in which a valid command has been typed, the CLI adds the command to the running configuration file. We recommend that you exit a configuration mode using the exit or end command.

Command Mode Summary

Table 3-1 summarizes information about the main command modes.

Table 3-1  Command Mode Summary  

Mode
Access Method
Prompt
Exit Method

EXEC

From the login prompt, enter your username and password.

switch#

To exit to the login prompt, use the exit command.

Global configuration

From EXEC mode, use the configure terminal command.

switch(config)#

To exit to EXEC mode, use the end or exit command or press Ctrl-Z.

Interface configuration

From global configuration mode, use an interface command and specify an interface with an interface command.

switch(config-if)#

To exit to global configuration mode, use the exit command.

To exit to EXEC mode, use the end command or press Ctrl-Z.

Subinterface configuration

From global configuration mode, specify a subinterface with an interface command.

switch(config-subif)#

To exit to global configuration mode, use the exit command.

To exit to EXEC mode, use the end command or press Ctrl-Z.

VDC configuration

From global configuration mode, use the vdc command and specify a VDC name.

switch(config-vdc)#

To exit to global configuration mode, use the exit command.

To exit to EXEC mode, use the end command or press Ctrl-Z.

VRF configuration

From global configuration mode, use the vrf command and specify a routing protocol.

switch(config-vrf)#

To exit to global configuration mode, use the exit command.

To exit to EXEC mode, use the end command or press Ctrl-Z.

EXEC for a nondefault VDC

From EXEC mode, use the switchto vdc command and specify a VDC.

switch-vdc2#

To exit to the default VDC, use the exit command or the switchback command.

EXEC for a nondefault VRF

From EXEC mode, use the routing-context vrf command and specify a VRF.

switch%red#

To exit to the default VRF, use the routing-context vrf default command.


Special Characters

Table 3-2 lists the characters that have special meaning in Cisco NX-OS text strings and should be used only in regular expressions or other special contexts.

Table 3-2 Special Characters  

Character
Description

%

Percent

#

Pound, hash, or number

...

Ellipsis

|

Vertical bar

< >

Less than or greater than

[ ]

Brackets

{ }

Braces


Keystroke Shortcuts

Table 3-3 lists command key combinations that can be used in both EXEC and configuration modes:

Table 3-3 Keystroke Shortcuts 

Key(s)
Description

Ctrl-A

Moves the cursor to the beginning of the line.

Ctrl-B

Moves the cursor one character to the left.
When you enter a command that extends beyond a single line, you can press the Left Arrow or Ctrl-B keys repeatedly to scroll back toward the system prompt and verify the beginning of the command entry, or you can press the Ctrl-A key combination.

Ctrl-C

Cancels the command and returns to the command prompt.

Ctrl-D

Deletes the character at the cursor.

Ctrl-E

Moves the cursor to the end of the line.

Ctrl-F

Moves the cursor one character to the right.

Ctrl-G

Exits to the previous command mode without removing the command string.

Ctrl-K

Deletes all characters from the cursor to the end of the command line.

Ctrl-L

Redisplays the current command line.

Ctrl-N

Displays the next command in the command history.

Ctrl-O

Clears the terminal screen.

Ctrl-P

Displays the previous command in the command history.

Ctrl-R

Redisplays the current command line.

Ctrl-T

Transposes the character to the left of the cursor with the character located to the right of the cursor.

Ctrl-U

Deletes all characters from the cursor to the beginning of the command line.

Ctrl-V

Removes any special meaning for the following keystroke. For example, press Ctrl-V before entering a question mark (?) in a regular expression.

Ctrl-W

Deletes the word to the left of the cursor.

Ctrl-X, H

Lists the history of commands you have entered.

When using this key combination, press and release the Ctrl and X keys together before pressing H.

Ctrl-Y

Recalls the most recent entry in the buffer (press keys simultaneously).

Ctrl-Z

Ends a configuration session, and returns you to EXEC mode.

When used at the end of a command line in which a valid command has been typed, the resulting configuration is first added to the running configuration file.

Displays the previous command in the command history.

Displays the next command in the command history.

Moves your cursor through the command history, either forward or backwards, to locate a command string.

?

Displays a list of available commands.

Tab

Completes the word for you after entering the first characters of the word, and then pressing the Tab key. All options that match are presented.

Use tabs to complete the following items:

Command names

Scheme names in the file system

Server names in the file system

Filenames in the file system

Example
switch(config)# xm<Tab> 
switch(config)# xml <Tab>
switch(config)# xml server

 
Example
switch(config)# c<Tab>
callhome        class-map       clock           cts
cdp             cli             control-plane

 
switch(config)# cl<Tab>
class-map   cli         clock 
switch(config)# cla<Tab>
switch(config)# class-map 

 
Example
switch# cd bootflash:<Tab>
bootflash:                bootflash://sup-1/        
bootflash://sup-remote/
bootflash:///             bootflash://sup-2/        
bootflash://sup-standby/
bootflash://module-5/     bootflash://sup-active/
bootflash://module-6/     bootflash://sup-local/
 
Example
switch# cd bootflash://mo<Tab> 
bootflash://module-5/  bootflash://module-6/
cvswitch# cd bootflash://module-

Abbreviating Commands

You can abbreviate commands and keywords by entering the first few characters of a command. The abbreviation must include sufficient characters to make it unique from other commands or keywords. If you are having trouble entering a command, check the system prompt and enter the question mark (?) for a list of available commands. You might be in the wrong command mode or using incorrect syntax.

Table 3-4 lists examples of command abbreviations.

Table 3-4 Examples of Command Abbreviations 

Command
Abbreviation

configure terminal

conf t

copy running-config startup-config

copy run start

interface ethernet 1/2

int e 1/2

show running-config

sh run


Identifying Your Location in the Command Hierarchy

Some features have configuration submode hierarchy nested more than one level. In these cases, you can display information about your present working context (PWC).

SUMMARY STEPS

1. where detail

DETAILED STEPS

 
Command
Purpose

Step 1 

where detail


Example:

switch# configure terminal
switch(config)# interface mgmt0
switch(config-if)# where detail
mode:                conf
                         interface mgmt0
  username:            admin
  vdc:                 switch
  routing-context vrf: default

Displays the PWC.

Using the no Form of a Command

Almost every configuration command has a no form that can be used to disable a feature, revert to a default value, or remove a configuration. The Cisco NX-OS command reference publications describe the function of the no form of the command whenever a no form is available.

This example shows how to disable a feature:

switch# configure terminal
switch(config)# feature bgp
switch(config)# no feature bgp

This example shows how to revert to the default value for a feature:

switch# configure terminal
switch(config)# banner motd #Welcome to the switch#
switch(config)# show banner motd
Welcome to the switch
switch(config)# no banner motd
switch(config)# show banner motd
User Access Verification

This example shows how to remove the configuration for a feature:

switch# configure terminal
switch(config)# role feature-group name security
switch(config-role-featuregrp)# feature aaa
switch(config-role-featuregrp)# feature radius
switch(config-role-featuregrp)# feature tacacs
switch(config-role-featuregrp)# exit
switch(config)# show role feature-group

feature group: L3
feature: router-bgp
feature: router-eigrp
feature: router-isis
feature: router-ospf
feature: router-rip

feature group: security
feature: aaa
feature: radius
feature: tacacs
switch(config)# no role feature-group name security
switch(config)# show role feature-group

feature group: L3
feature: router-bgp
feature: router-eigrp
feature: router-isis
feature: router-ospf
feature: router-rip

This example shows how to use the no form of a command in EXEC mode:

switch# system standby manual-boot
system standby manual-boot option enabled
switch# system no standby manual-boot
system standby manual-boot option disabled

Configuring CLI Variables

This section includes the following topics:

About CLI Variables

Configuring CLI Variables

About CLI Variables

The Cisco NX-OS software supports the definition and use of variables in CLI commands.

You can use CLI variables in the following ways: ï

Entered directly on the command line.

Passed to a script initiated using the run-script command. The variables defined in the parent shell are available for use in the child run-script command process (see the "Running a Command Script" section).

CLI variables have the following characteristics: ï

Cannot have nested references through another variable

Can exist only for the current session

Cisco NX-OS supports one predefined variable: TIMESTAMP. This variable refers to the time of execution of the command in the format YYYY-MM-DD-HH.MM.SS.


Note The TIMESTAMP variable name is case sensitive. All letters must be uppercase.


Configuring CLI Variables

You can define CLI session variables to persist only for the duration of your CLI session. These variables are useful for scripts that you execute periodically. You can reference the variable by enclosing the name in parentheses and preceding it with a dollar sign ($), for example $(variable-name).

SUMMARY STEPS

1. cli var name variable-name variable-text

2. show cli variables

DETAILED STEPS

 
Command
Purpose

Step 1 

cli var name variable-name variable-text


Example:

switch# cli var name testinterface ethernet 2/1

Configures the CLI session variable. The variable-name argument is alphanumeric, case sensitive, and has a maximum length is 31 characters. The variable-text argument is alphanumeric, case sensitive, can contain spaces, and has a maximum length of 200 characters.

Step 2 

show cli variables


Example:

switch# show cli variables

(Optional) Displays the CLI variable configuration.

Command Aliases

You can define command aliases to replace frequently used commands. The command aliases can represent all or part of the command syntax.


Note The Cisco NX-OS software provides one default alias, alias, which displays all user-defined aliases.


This section includes the following topics:

About Command Aliases

Defining Command Aliases

About Command Aliases

Command alias support has the following characteristics:

Command aliases are global for all user sessions.

Command aliases persist across reboots if you save them to the startup configuration.

Command alias translation always takes precedence over any keyword in any configuration mode or submode.

Command alias configuration takes effect for other user sessions immediately.

You cannot delete or change the default command alias alias, which aliases the show cli alias command.

You can nest aliases to a maximum depth of 1. One command alias can refer to another command alias that must refer to a valid command, not to another command alias.

A command alias always replaces the first command keyword on the command line.

You can define command aliases for commands in any command mode.

If you reference a CLI variable in a command alias, the current value of the variable appears in the alias, not the variable reference.

Defining Command Aliases

You can define command aliases for commonly used commands.

SUMMARY STEPS

1. configure terminal

2. cli alias name alias-name alias-text

3. exit

4. alias

5. copy running-config startup-config

DETAILED STEPS

 
Command
Purpose

Step 1 

configure terminal


Example:

switch# configure terminal

switch(config)#

Enters global configuration mode.

Step 2 

cli alias name alias-name alias-text


Example:

switch(config)# cli alias name ethint interface ethernet

Configures the command alias. The alias name is an alphanumeric string that is not case sensitive and must begin with an alphabetic character. The maximum length is 30 characters.

Step 3 

exit


Example:

switch(config)# exit

switch#

Exits global configuration mode.

Step 4 

alias


Example:

switch# alias

(Optional) Displays the command alias configuration.

Step 5 

copy running-config startup-config


Example:

switch# copy running-config startup-config

(Optional) Copies the running configuration to the startup configuration.

Command Scripts

You can create scripts of commands to perform multiple tasks.

This section includes the following topics:

Running a Command Script

Echoing Information to the Terminal

Echoing Information to the Terminal

Running a Command Script

You can create a list of command in a file and execute them from the CLI. You can use CLI variables in the command script (see the "Configuring CLI Variables" section).


Note You cannot create the script files at the CLI prompt. You can create the script file on a a remote device and copy it the Cisco NX-OS device. This section assumes that the script file resides in the bootflash:.


SUMMARY STEPS

1. run-script filename

DETAILED STEPS

 
Command
Purpose

Step 1 

run-script filename


Example:

switch# run-script testfile

Executes the commands in the file.

Echoing Information to the Terminal

You can echo information to the terminal, which is particularly useful from a command script. You can reference CLI variables and use formatting options in the echoed text. Table 3-5 lists the formatting options you can insert in the text.

Table 3-5 Formatting Options for the echo Command 

Formatting Option
Description

\b

Back spaces.

\c

Removes the new line character at the end of the text string.

\f

Inserts a form feed character.

\n

Inserts a new line character.

\r

Returns to the beginning of the text line.

\t

Inserts a horizontal tab character.

\v

Inserts a vertical tab character.

\\

Displays a backslash character.

\nnn

Displays the corresponding ASCII octal character.


SUMMARY STEPS

1. echo [-e] [text]

echo [backslash-interpret] [text]

DETAILED STEPS

 
Command
Purpose

Step 1 

echo [-e] [text]


Example:

switch# echo This is a test.

This is a test.

Displays information on the terminal. In Cisco NX-OS Release 4.0(2) and earlier releases, the -e keyword indicates that the text string contains formatting options (see Table 3-5). The text argument is alphanumeric, case sensitive and can contain blanks. The maximum length is 200 characters. The default is a blank line.

echo [backslash-interpret] [text]


Example:

switch# echo This is a test.

This is a test.

Displays information on the terminal. In Cisco NX-OS Release 4.0(3) and later releases, the backslash-interpret keyword indicates that the text string contains formatting options (see Table 3-5). The text argument is alphanumeric, case sensitive and can contain blanks. The maximum length is 200 characters. The default is a blank line.

Delaying Command Action

You can delay a command action for a period of time, which is particularly useful with in a command script.

SUMMARY STEPS

1. sleep seconds

DETAILED STEPS

 
Command
Purpose

Step 1 

sleep seconds


Example:

switch# sleep 30

Cause a delay for a number of second. The range is from 0 to 2147483647.

Context-Sensitive Help

The Cisco NX-OS software provides context-sensitive help in the CLI. You can use a question mark (?) at any point in a command to list the valid input options.

CLI uses the caret (^) symbol to isolate input errors. The ^ symbol appears at the point in the command string where you have entered an incorrect command, keyword, or argument.

Table 3-6 shows how to use error isolation and context-sensitive help when setting the clock.

Table 3-6 Context-Sensitive Help Example 

 
Command
Purpose

Step 1 

clock ?


Example:

switch# clock ?
  set  HH:MM:SS Current Time
switch# clock 

Displays the command syntax for the clock command in EXEC mode.

The switch output shows that the set keyword is required for using the clock command.

Step 2 

clock set ?


Example:

switch# clock set ?
  WORD  HH:MM:SS Current Time

switch# clock set 

Displays the command syntax for setting the time.

The help output shows that the current time is required for setting the clock and how to format the time.

Step 3 

clock set HH:MM:SS


Example:

switch# clock set 13:32:00<CR>
% Incomplete command
switch# 

Adds the current time.

Switch indicates the command is incomplete.

Step 4 

Ctrl-P or the Up Arrow


Example:

switch# <Ctrl-P>
switch# clock set 13:32:00

Displays the previous command that you entered.

Step 5 

clock set HH:MM:SS ?


Example:

switch# clock set 13:32:00 ?
  <1-31>     Day of the month
switch# clock set 13:32:00

Displays the additional arguments for the clock set command.

Step 6 

clock set HH:MM:SS day ?


Example:

switch# clock set 13:32:00 18 ?
  April      Month of the year
  August     Month of the year
  December   Month of the year
  February   Month of the year
  January    Month of the year
  July       Month of the year
  June       Month of the year
  March      Month of the year
  May        Month of the year
  November   Month of the year
  October    Month of the year
  September  Month of the year
switch# clock set 13:32:00 18

Displays the additional arguments for the clock set command.

Step 7 

clock set HH:MM:SS day month year


Example:

switch# clock set 13:32:00 18 April 08
                                  ^
% Invalid input detected at '^' marker.

Adds the date to the clock setting.

The CLI indicates an error with the caret symbol (^) at 08.

Step 8 

clock set HH:MM:SS day month year ?


Example:

switch# clock set 13:32:00 18 April ?
  <2000-2030>  Enter the year (no abbreviation)
switch# clock set 13:32:00 18 April

Displays the correct arguments for the year.

Step 9 

clock set HH:MM:SS day month year


Example:

switch# clock set 13:32:00 18 April 2008

Enters the correct syntax for the clock set command.

Understanding Regular Expressions

The Cisco NX-OS software supports regular expressions for search and filtering in the commands, such as the show commands. Regular expressions are case sensitive and allow for complex matching requirements.

This section includes the following topics:

Special Characters

Single-Character Patterns

Multiple-Character Patterns

Anchoring

Special Characters

You can also use other keyboard characters (such as ! or ~) as single-character patterns, but certain keyboard characters have special meanings when used in regular expressions. Table 3-7 lists the keyboard characters that have special meanings.

Table 3-7 Special Characters with Special Meaning 

Character
Special Meaning

.

Matches any single character, including white space.

*

Matches 0 or more sequences of the pattern.

+

Matches 1 or more sequences of the pattern.

?

Matches 0 or 1 occurrences of the pattern.

^

Matches the beginning of the string.

$

Matches the end of the string.

_ (underscore)

Matches a comma (,), left brace ({), right brace (}), left parenthesis ( ( ), right parenthesis ( ) ), the beginning of the string, the end of the string, or a space.


To use these special characters as single-character patterns, remove the special meaning by preceding each character with a backslash (\). This example contains single-character patterns that match a dollar sign ($), an underscore (_), and a plus sign (+), respectively:

\$ \_ \+

Single-Character Patterns

The simplest regular expression is a single character that matches the same single character in the command output. You can use any letter (A-Z, a-z) or digit (0-9) as a single-character pattern. You can specify a range of single-character patterns to match against command output.

To specify a range of single-character patterns, enclose the single-character patterns in square brackets ([ ]). For example, you can create a regular expression that matches a string containing one of the following letters: a, e, i, o, or u. Only one of these characters must exist in the string for pattern matching to succeed. In this case, [aeiou] matches any one of the five vowels of the lowercase alphabet, while [abcdABCD] matches any one of the first four letters of the lowercase or uppercase alphabet. You can simplify ranges by entering only the endpoints of the range separated by a dash (-). Also, you can including a caret (^) at the start of the range to match strings that do not include the range of characters.

Table 3-8 shows examples of regular expressions with ranges of characters.

Table 3-8 Example Expressions with Ranges of Characters 

Example
Description

[a-dA-D]

Matches the characters abcdABCD.

[a-dA-D\-]

Matches the characters abcdABCD and hyphen (-).

[a-dA-D\-\]]

Matches the characters abcdABDC, hyphen (-), and right square bracket (]).

[^a-dqsv]

Matches any letter except a-dqsv.

[^\]d]

Matches anything except a right square bracket (]) or the letter d.


Multiple-Character Patterns

You can also specify a pattern containing multiple characters by joining letters, digits, or keyboard characters that do not have special meanings. For example, a4% is a multiple-character regular expression.

With multiple-character patterns, the order is important. The regular expression a4% matches the character a followed by a 4 followed by a percent sign (%). If the string does not have a4%, in that order, pattern matching fails. The multiple-character regular expression a. (the character a followed by a period) uses the special meaning of the period character to match the letter a followed by any single character. With this example, the strings ab, a!, or a2 are all valid matches for the regular expression.

You can remove the special meaning of a special character by inserting a backslash before it. For example, when the expression a\. is used in the command syntax, only the string a. will be matched.

Anchoring

You can match a regular expression pattern against the beginning or the end of the string by "anchoring" these regular expressions to a portion of the string using the special characters shown in Table 3-9.

Table 3-9 Special Characters Used for Anchoring 

Character
Description

^

Matches the beginning of the string.

$

Matches the end of the string.


For example, the regular expression ^con matches any string that starts with con, and $sole matches any string that ends with sole.


Note The ^ symbol can also be used to indicate the logical function "not" when used in a bracketed range. For example, the expression [^abcd] indicates a range that matches any single letter, as long as it is not the letters a, b, c, or d.


Searching and Filtering show Command Output

Often, the output from show commands can be lengthy and cumbersome. The Cisco NX-OS software provides the means to search and filter the output so that you can easily locate information. The searching and filtering options follow a pipe character (|) at the end of the show command. You can display the options using the using the CLI context-sensitive help facility:

switch# show running-config | ?
  egrep    Egrep
  grep     Grep
  head     Stream Editor
  last     Display last lines
  less     Stream Editor
  no-more  Turn-off pagination for command output
  sed      Stream Editor
  wc       Count words, lines, characters
  begin    Begin with the line that matches
  count    Count number of lines
  exclude  Exclude lines that match
  include  Include lines that match

Filtering and Searching Keywords

The Cisco NX-OS CLI provides a set of keywords that you can use with the show commands to search and filter the command output (see Table 3-10).

Table 3-10 Filtering and Searching Keywords 

Keyword Syntax
Description
Example

begin string

Starts displaying at the line that contains text that matches the search string. The search string is case sensitive.

show version | begin Hardware

count

Displays the number of lines in the command output.

show running-config | count

exclude string

Displays all lines that do not include the search string. The search string is case sensitive.

show interface brief | exclude down

head [-n lines]

In Cisco NX-OS Release 4.0(2) and earlier releases, displays the beginning of the output for the number of lines specified. The default number of lines is 10.

show logging logfile | head -n 50

head [lines lines]

In Cisco NX-OS Release 4.0(3) and later releases, displays the beginning of the output for the number of lines specified. The default number of lines is 10.

show logging logfile | head lines 50

include string

Displays all lines that include the search string. The search string is case sensitive.

show interface brief | include up

last [lines]

Displays the end of the output for the number of lines specified. The default number of lines is 10.

show logging logfile | last lines 50

no-more

Displays all the output without stopping at the end of the screen with the --More-- prompt.

show interface brief | no-more

wc {-c | -l | -w}

In Cisco NX-OS Release 4.0(2) and earlier releases, displays counts of characters, lines, or words.

show file testoutput | wc -c

wc {bytes | lines | words}

In Cisco NX-OS Release 4.0(3) and later releases, displays counts of characters, lines, or words.

show file testoutput | wc bytes


grep and egrep Utilities

You can use the Global Regular Expression Print (grep) and Extended grep (egrep) command-line utilities to filter the show command output as follows:

{grep | egrep} [-A lines] [-B lines] [-c] [-i] [-n] [-v] [-w] [-x] expression

Table 3-11 describes the grep and egrep parameters.

Table 3-11 grep and egrep Parameters in Cisco NX-OS 4.0(2) and Earlier Releases 

Parameter
Description

-A lines

Specifies the number of lines to display after a matched line. The default is 0. The range is from 1 to 999.

-B lines

Specifies the number of lines to display before a matched line. The default is 0. The range is from 1 to 999.

-c

Displays only the total count of matched lines.

-i

Specifies to ignore the case difference in matched lines.

-n

Specifies to display the line number before each matched line.

-v

Displays lines that do not match the expression.

-w

Displays only lines that match a complete word.

-x

Displays only lines that match a complete line.

expression

Specifies a regular expression for searching the output.


Table 3-12 grep and egrep Parameters in Cisco NX-OS 4.0(3) and Later Releases 

Parameter
Description

count

Displays only the total count of matched lines.

ignore-case

Specifies to ignore the case difference in matched lines.

invert-match

Displays lines that do not match the expression.

line-exp

Displays only lines that match a complete line.

line-number

Specifies to display the line number before each matched line.

next lines

Specifies the number of lines to display after a matched line. The default is 0. The range is from 1 to 999.

prev lines

Specifies the number of lines to display before a matched line. The default is 0. The range is from 1 to 999.

word-exp

Displays only lines that match a complete word.

expression

Specifies a regular expression for searching the output.


less Utility

You can use the less utility to display the contents of the show command output one screen at a time. You can enter less commands at the : prompt. To display all less commands you can use, enter h at the : prompt.

sed Utility

You can use the Stream Editor (sed) utility to filter and manipulate the show command output as follows:

sed command

The command argument contains sed utility commands.

Searching and Filtering from the --More-- Prompt

You can search and filter output from --More-- prompts. To search and filter the show command output from a --More-- prompt, use the commands described in Table 3-13.

Table 3-13 --More-- Prompt Commands 

Commands
Description

[lines]<space>

Displays output lines for either the specified number of lines or the current screen size.

[lines]z

Displays output lines for either the specified number of lines or the current screen size. If you use the lines argument, that value becomes the new default screen size.

[lines]<return>

Displays output lines for either the specified number of lines or the current default number of lines. The initial default is 1 line. If you use the optional lines argument, that value becomes the new default number of lines to display for this command.

[lines]d or [lines]Ctrl+shift+D

Scrolls through output lines for either the specified number of lines or the current default number of lines. The initial default is 11 lines. If you use the optional lines argument, that value becomes the new default number of lines to display for this command.

q or Q or Ctrl-C

Exits the --More-- prompt.

[lines]s

Skips forward in the output for either the specified number of lines or the current default number of lines and displays a screen of lines. The default is 1 line.

[lines]f

Skips forward in the output for either the specified number of screens or the current default number of screens and displays a screen of lines. The default is 1 screen.

=

Displays the current line number.

[count]/expression

Skips to the line that matches the regular expression and displays a screen of output lines. Use the optional count argument to search for lines with multiple occurrences of the expression. This command sets the current regular expression that you can use in other commands.

[count]n

Skips to the next line that matches the current regular expression and displays a screen of output lines. Use the optional count argument to skip past matches.

{! | :!} shell-cmd

Executes the command specified in the shell-cmd argument in a subshell.

.

Repeats the previous command.


BIOS Loader> Prompt

When the supervisor modules power up, a specialized BIOS image automatically loads and tries to locate a valid kickstart image for booting the system. If a valid kickstart image is not found, the following BIOS loader prompt displays:

loader>

For information on how to load the Cisco NX-OS software from the loader> prompt, see the
Cisco Nexus 7000 Series NX-OS Troubleshooting Guide, Release 4.0.

Examples Using the CLI

This section includes the following topics:

Defining Command Aliases

Using CLI Session Variables

Using the System-Defined Timestamp Variable

Running a Command Script

Defining Command Aliases

This example shows how to define command aliases:

cli alias name ethint interface ethernet
cli alias name shintbr show interface brief
cli alias name shintupbr shintbr | include up | include ethernet

This example shows how to use a command alias:

switch# configure terminal
switch(config)# ethint 2/3
switch(config-if)#

Using CLI Session Variables

You can reference a variable using the syntax $(variable-name).

This example shows how to reference a user-defined CLI session variable:

switch# show interface $(testinterface)
Ethernet2/1 is down (Administratively down)
  Hardware is 10/100/1000 Ethernet, address is 0000.0000.0000 (bia 0019.076c.4da
c)
  MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA
  auto-duplex, auto-speed
  Beacon is turned off
  Auto-Negotiation is turned on
  Input flow-control is off, output flow-control is off
  Auto-mdix is turned on
  Switchport monitor is off
  Last clearing of "show interface" counters never
  5 minute input rate 0 bytes/sec, 0 packets/sec
  5 minute output rate 0 bytes/sec, 0 packets/sec
  L3 in Switched:
    ucast: 0 pkts, 0 bytes - mcast: 0 pkts, 0 bytes
  L3 out Switched:
    ucast: 0 pkts, 0 bytes - mcast: 0 pkts, 0 bytes
  Rx
    0 input packets 0 unicast packets 0 multicast packets
    0 broadcast packets 0 jumbo packets 0 storm suppression packets
    0 bytes
  Tx
    0 output packets 0 multicast packets
    0 broadcast packets 0 jumbo packets
    0 bytes
    0 input error 0 short frame 0 watchdog
    0 no buffer 0 runt 0 CRC 0 ecc
    0 overrun  0 underrun 0 ignored 0 bad etype drop
    0 bad proto drop 0 if down drop 0 input with dribble
    0 input discard
    0 output error 0 collision 0 deferred
    0 late collision 0 lost carrier 0 no carrier
    0 babble
    0 Rx pause 0 Tx pause 0 reset

Using the System-Defined Timestamp Variable

This example uses $(TIMESTAMP) when redirecting show command output to a file.

switch# show running-config > rcfg.$(TIMESTAMP)
Preparing to copy....done
switch# dir
       12667     May 01 12:27:59 2008  rcfg.2008-05-01-12.27.59

Usage for bootflash://sup-local
8192 bytes used
20963328 bytes free
20971520 bytes total

Running a Command Script

This example displays the CLI commands specified in the script file:

switch# show file testfile
configure terminal
interface ethernet 2/1
no shutdown
end
show interface ethernet 2/1

This example displays the run-script command execution output:

switch# run-script testfile
`configure terminal`
`interface ethernet 2/1`
`no shutdown`
`end`
`show interface ethernet 2/1 `
Ethernet2/1 is down (Link not connected)
  Hardware is 10/100/1000 Ethernet, address is 0019.076c.4dac (bia 0019.076c.4dac)
  MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA
  Port mode is trunk
  auto-duplex, auto-speed
  Beacon is turned off
  Auto-Negotiation is turned on
  Input flow-control is off, output flow-control is off
  Auto-mdix is turned on
  Switchport monitor is off
  Last clearing of "show interface" counters 1d26.2uh
  5 minute input rate 0 bytes/sec, 0 packets/sec
  5 minute output rate 0 bytes/sec, 0 packets/sec
  Rx
    0 input packets 0 unicast packets 0 multicast packets
    0 broadcast packets 0 jumbo packets 0 storm suppression packets
    0 bytes
  Tx
    0 output packets 0 multicast packets
    0 broadcast packets 0 jumbo packets
    0 bytes
    0 input error 0 short frame 0 watchdog
    0 no buffer 0 runt 0 CRC 0 ecc
    0 overrun  0 underrun 0 ignored 0 bad etype drop
    0 bad proto drop 0 if down drop 0 input with dribble
    0 input discard
    0 output error 0 collision 0 deferred
    0 late collision 0 lost carrier 0 no carrier
    0 babble
    0 Rx pause 0 Tx pause 0 reset

Additional References

For additional information related to implementing Feature-1, see the following sections:

Related Documents

Related Documents

Related Topic
Document Title

Licensing

Cisco Nexus 7000 Series NX-OS Licensing Guide, Release 4.0

Command reference

Cisco Nexus 7000 Series NX-OS Fundamentals Command Reference, Release 4.0