CCNA online course

How to Display and Manage Cisco IOS Command History

Learn how Cisco IOS command history works, including show history, command recall, session and line configuration, verification, troubleshooting, and security considerations.

Cisco IOS keeps recently entered commands in an in-memory command history buffer for each CLI session. This lets you recall and reuse commands instead of typing long commands repeatedly. It is especially useful during troubleshooting, when you may need to repeat variations of show, ping, or interface commands.

Command history is associated with the active terminal session. It is not a replacement for the saved device configuration, a change record, or an external command log. When the session ends, its interactive history is normally no longer available in a new session.

How Cisco IOS Command History Works

The history buffer stores a limited number of commands that you enter through one console, VTY, or other terminal session. As new commands are added, older commands can be removed when the buffer reaches its configured capacity.

History reduces repetitive typing and helps prevent errors when reusing long commands. You can recall a command, change part of it, and execute the revised version. For example, you might recall a command for GigabitEthernet0/1, edit the interface identifier, and run it for another interface.

History is usually session-specific. A command entered through one SSH connection will not normally appear in a different SSH connection, even if both connections use the same username. It also does not automatically show commands from a previous session.

Displaying the Command History

From privileged EXEC mode, use show history to display the commands currently retained in the active session's history buffer.

Router> enable
Router# show history

The output is a list of commands held in the buffer. The exact format can vary by IOS platform and release. The list is limited by the current history-buffer size, so it may not contain older commands that have already been overwritten. If history has been disabled with a size of zero, there may be no retained commands.

Example: reviewing a troubleshooting session

  1. Enter privileged EXEC mode with enable.
  2. Run show history.
  3. Identify a previously used show or ping command.
  4. Recall the command interactively or type it again if it is no longer in the buffer.

Recalling and Editing Commands

IOS provides keyboard shortcuts for moving through the history buffer:

  • Ctrl-P: select the previous command in history.
  • Ctrl-N: select the next command in history.

Up-arrow and down-arrow keys commonly perform the same functions. The terminal emulator must send the escape sequences that IOS expects, however. Behavior can vary among SSH clients, console applications, browser-based terminals, and terminal-emulation settings.

To reuse a command, press Ctrl-P or the up-arrow key until the desired command appears at the prompt. Move the cursor and edit the command as needed, then press Enter to execute the revised command.

Router# show interfaces GigabitEthernet0/1
Router# show interfaces GigabitEthernet0/1
             ^ edit the interface identifier if needed
Router# show interfaces GigabitEthernet0/2

The example illustrates the workflow rather than a particular cursor-control method. Your terminal client may use different keys for moving the cursor within the recalled line.

Command History Commands and Shortcuts

Command or key sequenceIOS modePurposeScopeNotes
show historyPrivileged EXECDisplays commands retained in the history bufferCurrent sessionOlder commands may not be present
terminal history size <0-256>EXECChanges history capacityCurrent terminal sessionA value of 0 disables storage
history size <0-256>Line configurationSets history capacity for connections using a lineConfigured console, auxiliary, or VTY lineApplies to applicable sessions using that line
no history sizeLine configurationRemoves an explicit line-level history settingConfigured lineSupported behavior can vary by IOS release; the line returns to default behavior
Ctrl-P or up-arrowCLI inputSelects the previous commandCurrent sessionArrow keys depend on terminal-emulator support
Ctrl-N or down-arrowCLI inputSelects the next commandCurrent sessionArrow keys depend on terminal-emulator support

Changing History Size for the Current Session

The EXEC command terminal history size changes the command-history capacity for the terminal session in which you enter it.

Router# terminal history size 50

This example allows the active session to retain up to 50 entries. The commonly supported IOS range is 0 through 256 entries, and the typical default is 10 entries. Always verify the accepted range and default on the specific IOS platform and software release.

A value of zero disables command-history storage for the current session:

Router# terminal history size 0

This setting is temporary. It does not permanently modify every console or VTY line, and it does not necessarily affect other users' active sessions. Use it when a session requires reduced interactive retention, but remember that it also removes the convenience of recalling commands.

Example: increasing history during remote troubleshooting

  1. From EXEC mode, enter terminal history size 50.
  2. Perform the troubleshooting work and enter multiple commands.
  3. Run show history to confirm that more commands can be retained.

Configuring History on Console and VTY Lines

A console line is the physical local-management line, commonly identified as line console 0. A VTY line is a virtual terminal line used for remote access such as SSH or Telnet. An auxiliary line may also exist on some devices.

Use the line-configuration command history size to establish a history capacity for connections using a particular line.

Console example

Router# configure terminal
Router(config)# line console 0
Router(config-line)# history size 50

VTY example

Router# configure terminal
Router(config)# line vty 0 4
Router(config-line)# history size 50

The VTY range must match the lines used by the device and IOS release. Some devices have additional VTY lines, such as line vty 5 15, that may need separate configuration.

Line configuration establishes a persistent setting in the device configuration for future connections through that line. It is different from terminal history size, which changes only the active session. Save the configuration if the line setting should survive a reload.

Router# copy running-config startup-config

To remove an explicit line-level setting when supported, use:

Router# configure terminal
Router(config)# line vty 0 4
Router(config-line)# no history size

Removing the setting causes the line to use the platform's default behavior. Check the command reference for the particular IOS release if the device rejects the command or displays different behavior.

Current Session Versus Persistent Line Settings

Setting methodWhere configuredWho is affectedPersistenceTypical use case
terminal history sizeEXEC modeThe current terminal sessionTemporary; normally ends with the sessionTemporarily increase history while troubleshooting or disable it for a sensitive task
history sizeConsole, auxiliary, or VTY line configurationConnections using the configured line or line rangeStored in the running configuration; save it for reload persistenceProvide a consistent history capacity for console or SSH users

Verifying Terminal and Line Behavior

Use several views to determine whether history behavior comes from the current session, the configured line, or the client software.

  • show history confirms which commands are currently retained.
  • show terminal displays relevant properties of the current terminal session when supported by the platform. Look for terminal-related settings, including history information.
  • show running-config | section line shows applicable line configuration, including explicit history size commands when present.
Router# show terminal
Router# show history
Router# show running-config | section line

When checking a remote user, inspect the line range associated with that connection. A setting under line console 0 does not establish the same behavior for VTY-based SSH sessions.

Practical Workflows

Reuse and modify a long interface command

  1. Press Ctrl-P or the up-arrow key until the long command appears.
  2. Edit the interface identifier or another option.
  3. Review the complete line carefully.
  4. Press Enter to run the updated command.

Disable history during a sensitive maintenance task

  1. Enter terminal history size 0 in the active session.
  2. Perform the required work without relying on interactive command recall.
  3. Restore an appropriate history size afterward if the session remains open.
Router# terminal history size 0
! Perform sensitive maintenance
Router# terminal history size 10

Disabling the IOS history buffer does not stop external systems from recording activity.

Security and Operational Considerations

Commands containing passwords, secrets, community strings, API tokens, or other sensitive values can remain visible in the active history buffer. Avoid placing sensitive values directly on the command line when a safer credential-handling method is available.

Setting the session history size to zero can be appropriate for a sensitive or shared operational session. The tradeoff is that operators cannot recall previous commands, so typing errors may become more likely. Plan the work accordingly.

Clearing or ending a CLI session does not necessarily erase records already sent to external systems. Terminal recording, AAA accounting, syslog, and command-auditing systems may retain administrative activity according to their own policies. Treat command history as only one possible place where command text may exist.

Troubleshooting Command History

show history lists fewer commands than expected

  • The buffer may have a small capacity.
  • Older commands may have been overwritten by newer commands.
  • History may be disabled with a size of zero.
  • You may be in a different session from the one where the commands were entered.

Run show history, set an appropriate value with terminal history size, and inspect the applicable line configuration if the behavior should persist for future sessions.

Up-arrow does not recall commands

  • Test Ctrl-P and Ctrl-N, which are IOS-native history shortcuts.
  • Verify the terminal emulator's keyboard and emulation settings.
  • Confirm that show history contains commands.
  • Try a different SSH client or console application if the client is not sending the expected arrow-key escape sequence.

A configured history size disappears after reconnecting

This usually happens when terminal history size was used. That command affects only the session in which it was entered. Configure history size under the relevant console or VTY line, save the configuration, and test with a new connection.

A sensitive command is visible in history

The command was probably entered while history was enabled and the session is still active. Do not expose or reuse the sensitive value. For future sensitive sessions, use terminal history size 0 where appropriate, use safer credential methods, and account for external logging and auditing.

Exam-Relevant Notes

  • show history displays commands in the current session's history buffer; it does not display the saved configuration.
  • terminal history size is an EXEC-level, current-session setting.
  • history size is a line-configuration setting for console, auxiliary, or VTY access.
  • terminal history size 0 disables history storage for the active session.
  • Ctrl-P recalls the previous command, and Ctrl-N moves toward the next command.
  • Arrow-key behavior depends on the terminal emulator, while Ctrl-P and Ctrl-N are the more portable IOS shortcuts.

Related Cisco IOS Skills

Command history is one part of effective IOS administration. For related management topics, review configuring passwords in IOS, configuring NTP on a Cisco device, and configuring OSPF.