H3C Comware 命令行基础:视图、undo 与保存 - 夜莺博客

H3C Comware 命令行基础:视图、undo 与保存

H3C switches running Comware look superficially like Cisco IOS, but the view hierarchy, the undo mechanism and the way output is filtered follow their own logic - and a newcomer who assumes IOS habits will spend the first hour typing commands that simply do not exist. This guide, based on the official H3C S5120-LI configuration guide, covers the Comware CLI essentials you need before anything else works: view navigation, undo commands, saving configuration, command history, screen paging control, and the regular-expression filters that make display output readable.

Comware CLI and the View Hierarchy

Comware CLI is organised into levels called views, and you must be in the right view before a command is accepted. Typing a configuration command from the wrong view produces an "Unrecognized command" error that has nothing to do with syntax:

  • User view: prompt <H3C>. Only display and test commands are available (display, ping, tracert, telnet, save).
  • System view: prompt [H3C], entered with system-view. This is the gateway to all global configuration.
  • Feature views: interface view, VLAN view, ACL view and so on, entered from system view one level at a time - for example interface GigabitEthernet1/0/1, vlan 10, acl number 2000.

Move up one level with quit. To jump straight from any view back to user view, press Ctrl+Z or type return. The prompt itself is the status indicator: the text inside the angle brackets or square brackets is the device name, and the bracket shape tells you which of the two top-level views you are in. A common workflow looks like this:

<H3C> system-view
[H3C] sysname SW-CORE-01
[SW-CORE-01] interface GigabitEthernet1/0/1
[SW-CORE-01-GigabitEthernet1/0/1] port link-type access
[SW-CORE-01-GigabitEthernet1/0/1] port access vlan 10
[SW-CORE-01-GigabitEthernet1/0/1] quit
[SW-CORE-01] quit
<SW-CORE-01>

Comware accepts abbreviated commands as long as the abbreviation is unambiguous, which is what makes dis cu work for display current-configuration and sys work for system-view. The Tab key completes a partially typed keyword, and ? lists what is available at that position - either the next keyword or, after a space, the allowed values. ? is the single most useful key on a Comware device, because it is context sensitive: it shows only the commands valid in the view you are actually in.

undo Commands: Restoring Defaults and Deleting Configuration

Prefixing a command with undo gives its inverse, and almost every configuration command has one. It is used to restore the default state, disable a feature, or delete configuration. For example, info-center enable starts the information centre while undo info-center enable stops it, and a single ACL rule is removed with undo rule 1:

[H3C] undo info-center enable
[H3C-acl-basic-2000] undo rule 1
[H3C-GigabitEthernet1/0/1] undo port access vlan 10

Three behaviours are worth internalising. First, undo with no additional keywords removes the whole object - undo vlan 10 deletes VLAN 10, not just its description. Second, on interfaces the default command resets the entire interface to its factory configuration, which is faster than issuing a dozen undo statements when you are repurposing a port. Third, undo only changes the running configuration; the effect is still not permanent until you save, which brings us to the next section.

Saving Configuration and Command History

display commands and reset commands execute once and are not saved; every other configuration change must be written to the configuration file with save, or it is lost at the next reboot. This is the single most common mistake made by engineers arriving from platforms that save automatically:

<H3C> save
The current configuration will be written to the device.
Are you sure to continue? [Y/N]: y
Now saving the current configuration to the slot 0.
Save the configuration successfully.

Related commands complete the picture. display current-configuration shows the running configuration, display saved-configuration shows what was loaded at startup, and display startup shows which file will be loaded at the next boot - the three commands that answer "did my change survive?" without a reboot. reset saved-configuration erases the startup file, which is how a factory reset is performed from the CLI.

The device keeps a configurable number of previous commands, ten per user by default, recalled with the up and down arrow keys. Increase it when you are doing long troubleshooting sessions:

<H3C> display history-command
[H3C] history-command max-size 20

Useful shell-level keys: Ctrl+C aborts the current command, Ctrl+C also breaks out of a ping with a large count, and the left/right arrows move the cursor inside the line so you can fix a typo without retyping the whole command. If you paste a multi-line configuration block, Comware processes each line separately - there is no IOS-like paste mode, so a slow terminal emulator can occasionally drop characters in long pastes.

Screen Paging and Output Filtering

When output exceeds one screen, the device pages automatically (24 lines per screen by default): press the space bar for the next page, Enter for the next line, and any other key to abandon the output. Disable paging for the current user session when you are scripting or copying output:

<H3C> screen-length disable
<H3C> screen-length 40

Filtering is where Comware earns its keep. The pipe operator supports three filters - include, exclude and begin:

<H3C> display current-configuration | include vlan
<H3C> display current-configuration | exclude password
<H3C> display logbuffer | begin 2026-08-29
<H3C> display ip routing-table | include 172.16.10
<H3C> display interface brief | exclude down

include shows only matching lines, exclude removes matching lines, and begin starts the display at the first matching line and continues to the end. All three take regular expressions, which is the part people miss: ^string anchors to the start of a line, string$ to the end, [1-3] matches a character range, and . matches any single character. Combining an anchor with include is how you extract, say, every interface line from a long display current-configuration without scrolling:

<H3C> display current-configuration | include ^interface
<H3C> display current-configuration | include ^ vlan
<H3C> display current-configuration | exclude ^#

Command Levels and Privilege

Comware classifies commands by privilege level (0 to 3 by default, where 3 is manage level). A user's level determines which views and commands are reachable, which is why a level-1 user can run display but not enter system view. Elevate the current session with the super command and the password configured by super password:

<H3C> super 3
Password:
<H3C>
[H3C] super password level 3 simple MySecret

Line-level authentication is configured per access channel. On Comware V5 platforms the console line is user-interface aux 0; on Comware V7 it is renamed user-interface console 0, and remote access is always user-interface vty 0 4:

[H3C] user-interface aux 0
[H3C-ui-aux0] authentication-mode scheme
[H3C-ui-aux0] quit
[H3C] user-interface vty 0 4
[H3C-ui-vty0-4] authentication-mode scheme
[H3C-ui-vty0-4] protocol inbound ssh

Everyday Verifying Commands

The Comware equivalents of the commands you will run first on any new device:

<H3C> display version
<H3C> display device
<H3C> display interface brief
<H3C> display ip interface brief
<H3C> display vlan
<H3C> display mac-address
<H3C> display arp all
<H3C> display logbuffer
<H3C> display diagnostic-information

Two of those deserve a note. display interface brief is the fastest way to see link state, speed, duplex and the access VLAN of every port on the switch, and display diagnostic-information collects a large set of outputs into one dump - useful to attach to a support case, slow to run on a busy device. On a stable network, display counters interface and reset counters interface give you a clean window for measuring error rates.

File System and Configuration Backup

Comware exposes a small file system, not just a configuration buffer. The startup configuration lives as a file in flash, and the file system commands are how you inspect, copy and back it up:

<H3C> dir
<H3C> display startup
<H3C> copy startup.cfg flash:/backup-2026-09.cfg
<H3C> tftp 192.168.1.100 put flash:/startup.cfg startup.cfg
<H3C> startup saved-configuration flash:/startup.cfg

Backing up before a maintenance window is not optional on Comware, because there is no automatic per-command rollback the way Junos or IOS-XE with configuration replace has. The three-step ritual - save, copy the startup file to a TFTP server, and record display version - is what lets you recover a device whose configuration was truncated by a bad paste. If you use an IRF stack, the configuration file is shared across members, so a single backup covers the whole logical device.

Terminal Monitoring and Debugging

By default, log and debug output is sent to the console and the log buffer, but not to a remote Telnet or SSH session. Enable it explicitly for the session you are working in:

<H3C> terminal monitor
<H3C> terminal logging
<H3C> terminal debugging
<H3C> display logbuffer reverse

terminal monitor mirrors log messages to your terminal, terminal debugging mirrors debug output, and display logbuffer reverse shows the log with the newest entries first so you do not have to scroll. Treat debugging commands with the same caution you would on any platform: they consume CPU, the output can flood a slow SSH session, and they should be turned off with undo debugging all the moment you have the data you need. A safer sequence is to capture the log buffer first, then enable a narrow debug filter only for the module in question.

Common Mistakes and How to Avoid Them

  • Configuring from user view. If a command is rejected and you are certain the syntax is right, check the prompt before anything else.
  • Rebooting before save. Verify with display startup and display saved-configuration that the file you expect is the one that will load.
  • Assuming IOS keyword names. Comware uses port link-type access rather than switchport mode access, display rather than show, and undo rather than no.
  • Filtering with the wrong tool. include keeps matching lines, exclude removes them; mixing the two up while hunting a rogue password line in a configuration dump wastes real time.
  • Forgetting that screen-length disable is per session, not global - a new terminal window starts paging again.

Frequently Asked Questions

How do I leave system view quickly? Press Ctrl+Z or type return. quit moves up only one level.

Does undo work on display commands? No. undo applies to configuration commands; display and reset commands have no undo form.

Where is the equivalent of IOS show run? display current-configuration, usually abbreviated to dis cu.

Can I copy a configuration file to a TFTP server? Yes - Comware includes a file system with dir, copy, tftp and ftp clients; use the file system commands rather than expecting a single backup command.

More hands-on H3C material: H3C IRF 堆叠配置与故障排查 and H3C 光模块与光链路运维指导. If you work across both Chinese vendor CLIs, the H3C Comware vs Huawei VRP Command Mapping Table and the HPE Comware OS Basics: FlexFabric Switch CLI Guide translate the same concepts onto neighbouring platforms.

原文链接:https://www.h3c.com/cn/d_201108/723390_30005_0.htm