Using the Command-Line Interface
This chapter describes the command-line interface (CLI) and how to use it to configure your device.
Understanding Command Modes
The user interface is divided into many different modes. The commands available to you depend on which mode you are currently in. Enter a question mark (?) at the system prompt to obtain a list of commands available for each command mode.
When you start a session on the switch, you begin in user mode, often called user EXEC mode. Only a limited subset of the commands are available in user EXEC mode. For example, most of the user EXEC commands are one-time commands, such as show commands, which show the current configuration status, and clear commands, which clear counters or interfaces. The user EXEC commands are not saved when the switch reboots.
To have access to all commands, you must enter privileged EXEC mode. Normally, you must enter a password to enter privileged EXEC mode. From this mode, you can enter any privileged EXEC command or enter global configuration mode.
Using the configuration modes (global and interface), you can make changes to the running configuration. If you save the configuration, these commands are stored and used when the device reboots. To access the various configuration modes, you must start at global configuration mode. From global configuration mode, you can enter interface configuration mode and line configuration mode.
This table describes the main command modes, how to access each one, the prompt you see in that mode, and how to exit the mode. The examples in the table use the hostname Device.
Mode |
Access Method |
Prompt |
Exit Method |
About This Mode |
---|---|---|---|---|
User EXEC |
Begin a session with your device. |
|
Enter exit or quit . |
Use this mode to
|
Privileged EXEC |
While in user EXEC mode, enter the enable command. |
|
Enter exit to exit. |
Use this mode to verify commands that you have entered. Use a password to protect access to this mode. |
Global configuration |
While in privileged EXEC mode, enter the configure command. |
|
To exit to privileged EXEC mode, enter exit or end , or press Ctrl-Z. |
Use this mode to configure parameters that apply to the entire switch. |
Ethernet interface configuration |
While in global configuration mode, enter the interface ethernet command (with a specific interface). |
|
To exit to global configuration mode, enter exit . To return to privileged EXEC mode, press Ctrl-Z or enter end . |
Use this mode to configure parameters for the Ethernet ports. |
VLAN configuration |
While in global configuration mode, enter the vlan vlan-id command. |
|
To exit to global configuration mode, enter the exit command. To return to privileged EXEC mode, press Ctrl-Z or enter end . |
Use this mode to configure VLAN parameters. |
AAA configuration |
While in global configuration mode, enter the aaa command. |
|
To exit to global configuration mode, enter the exit command. To return to privileged EXEC mode, press Ctrl-Z or enter end . |
Use this mode to setup the domain. |
RADIUS configuration |
While in global configuration mode, enter the radius host radius-name command. |
|
To exit to global configuration mode, enter the exit command. To return to privileged EXEC mode, press Ctrl-Z or enter end . |
Use this mode to configure RADIUS parameters. |
VLAN interface configuration |
While in global configuration mode, enter the interface vlan-interface vlan-id command. |
|
To exit to global configuration mode, enter the exit command. To return to privileged EXEC mode, press Ctrl-Z or enter end . |
Use this mode to configure VLAN Layer 3 interface |
Understanding the Help System
You can enter a question mark (?) at the system prompt to display a list of commands available for each command mode. You can also obtain a list of associated keywords and arguments for any command.
Command |
Purpose |
---|---|
help |
Obtains a brief description of the help system in any command mode. |
abbreviated-command-entry ?
|
Obtains a list of commands that begin with a particular character string. |
abbreviated-command-entry <Tab>
|
Completes a partial command name. |
?
|
Lists all commands available for a particular command mode. |
command ?
|
Lists the associated keywords for a command. |
command keyword ?
|
Lists the associated arguments for a keyword. |
Understanding Abbreviated Commands
You need to enter only enough characters for the switch to recognize the command as unique.
This example shows how to enter the show version command in an abbreviated form:
Device# show ver
Understanding no Forms of Commands
Almost every configuration command also has a no form. In general, use the no form to disable a feature or function or reverse the action of a command. For example, the no shutdown interface configuration command reverses the shutdown of an interface. Use the command without the keyword no to re-enable a disabled feature or to enable a feature that is disabled by default.
Understanding CLI Error Messages
This table lists some error messages that you might encounter while using the CLI to configure your device.
Error Message |
Meaning |
How to Get Help |
---|---|---|
|
You did not enter all the keywords or values required by this command. |
Re-enter the command followed by a question mark (?) with a space between the command and the question mark. The possible keywords that you can enter with the command appear. |
|
You entered the command incorrectly. The caret (^) marks the point of the error. |
Enter a question mark (?) to display all the commands that are available in this command mode. The possible keywords that you can enter with the command appear. |
Using Editing Features
This section describes the editing features that can help you manipulate the command line.
Editing Commands through Keystrokes
This table shows the keystrokes that you need to edit command lines. These keystrokes are optional.
![]() Note |
The arrow keys function only on ANSI-compatible terminals such as VT100s. |
Capability |
Keystroke |
Purpose |
||
---|---|---|---|---|
Move around the command line to make changes or corrections. |
Press Ctrl-B, or press the left arrow key. |
Moves the cursor back one character. |
||
Press Ctrl-F, or press the right arrow key. |
Moves the cursor forward one character. |
|||
Press Ctrl-A. |
Moves the cursor to the beginning of the command line. |
|||
Press Ctrl-E. |
Moves the cursor to the end of the command line. |
|||
Press Esc B. |
Moves the cursor back one word. |
|||
Press Esc F. |
Moves the cursor forward one word. |
|||
Press Ctrl-T. |
Transposes the character to the left of the cursor with the character located at the cursor. |
|||
Recall commands from the buffer and paste them in the command line. The switch provides a buffer with the last ten items that you deleted. |
Press Ctrl-Y. |
Recalls the most recent entry in the buffer. |
||
Press Esc Y. |
Recalls the next buffer entry. The buffer contains only the last 10 items that you have deleted or cut. If you press Esc Y more than ten times, you cycle to the first buffer entry. |
|||
Delete entries if you make a mistake or change your mind. |
Press the Delete or Backspace key. |
Erases the character to the left of the cursor. |
||
Press Ctrl-D. |
Deletes the character at the cursor. |
|||
Press Ctrl-K. |
Deletes all characters from the cursor to the end of the command line. |
|||
Press Ctrl-U or Ctrl-X. |
Deletes all characters from the cursor to the beginning of the command line. |
|||
Press Ctrl-W. |
Deletes the word to the left of the cursor. |
|||
Press Esc D. |
Deletes from the cursor to the end of the word. |
|||
Capitalize or lowercase words or capitalize a set of letters. |
Press Esc C. |
Capitalizes at the cursor. |
||
Press Esc L. |
Changes the word at the cursor to lowercase. |
|||
Press Esc U. |
Capitalizes letters from the cursor to the end of the word. |
|||
Designate a particular keystroke as an executable command, perhaps as a shortcut. |
Press Ctrl-V or Esc Q. |
|||
Scroll down a line or screen on displays that are longer than the terminal screen can display.
|
Press the Return key. |
Scrolls down one line. |
||
Press the Space bar. |
Scrolls down one screen. |
|||
Redisplay the current command line if the switch suddenly sends a message to your screen. |
Press Ctrl-L or Ctrl-R. |
Redisplays the current command line. |
Editing Command Lines that Wrap
You can use a wraparound feature for commands that extend beyond a single line on the screen. When the cursor reaches the right margin, the command line shifts ten spaces to the left. You cannot see the first ten characters of the line, but you can scroll back and check the syntax at the beginning of the command. The keystroke actions are optional.
To scroll back to the beginning of the command entry, press Ctrl-B or the left arrow key repeatedly. You can also press Ctrl-A to immediately move to the beginning of the line.
![]() Note |
The arrow keys function only on ANSI-compatible terminals such as VT100s. |
In this example, the access-list global configuration command entry extends beyond one line. When the cursor first reaches the end of the line, the line is shifted ten spaces to the left and redisplayed. The dollar sign ($) shows that the line has been scrolled to the left. Each time the cursor reaches the end of the line, the line is again shifted ten spaces to the left.
Device(config)# access-list 101 permit tcp 131.108.2.5 255.255.255.0 131.108.1
Device(config)# $ 101 permit tcp 131.108.2.5 255.255.255.0 131.108.1.20 255.25
Device(config)# $t tcp 131.108.2.5 255.255.255.0 131.108.1.20 255.255.255.0 eq
Device(config)# $108.2.5 255.255.255.0 131.108.1.20 255.255.255.0 eq 45
After you complete the entry, press Ctrl-A to check the complete syntax before pressing the Return key to execute the command. The dollar sign ($) appears at the end of the line to show that the line has been scrolled to the right:
Device(config)# access-list 101 permit tcp 131.108.2.5 255.255.255.0 131.108.1$
The software assumes that you have a terminal screen that is 80 columns wide. If you have a width other than that, use the terminal width privileged EXEC command to set the width of your terminal.
Use line wrapping with the command history feature to recall and modify previous complex command entries.
Searching and Filtering Output of show and more Commands
You can search and filter the output for show and more commands. This is useful when you need to sort through large amounts of output or if you want to exclude output that you do not need to see. Using these commands is optional.
To use this functionality, enter a show or more command followed by the pipe character (|), one of the keywords begin , include , or exclude , and an expression that you want to search for or filter out:
command | {begin | include | exclude} regular-expression
Expressions are case sensitive. For example, if you enter | exclude output , the lines that contain output are not displayed, but the lines that contain Output appear.
This example shows how to include in the output display only lines where the expression protocol appears:
Device# show interfaces | include protocol
Vlan1 is up, line protocol is up
Vlan10 is up, line protocol is down
GigabitEthernet1/0/1 is up, line protocol is down
GigabitEthernet1/0/2 is up, line protocol is up
Accessing the CLI through a Console Connection or through Telnet
Before you can access the CLI, you must connect a terminal or a PC to the device console or connect a PC to the Ethernet management port and then power on the device, as described in the hardware installation guide that shipped with your device.
CLI access is available before device setup. After your device is configured, you can access the CLI through a remote Telnet session or SSH client.
You can use one of these methods to establish a connection with the device:
-
Connect the device console port to a management station or dial-up modem, or connect the Ethernet management port to a PC. For information about connecting to the console or Ethernet management port, see the device hardware installation guide.
-
Use any Telnet TCP/IP or encrypted Secure Shell (SSH) package from a remote management station. The device must have network connectivity with the Telnet or SSH client, and the device must have an enable secret password configured.
The device supports up to 16 simultaneous Telnet sessions. Changes made by one Telnet user are reflected in all other Telnet sessions.
The device supports up to five simultaneous secure SSH sessions.
After you connect through the console port, through the Ethernet management port, through a Telnet session or through an SSH session, the user EXEC prompt appears on the management station.