Most people don’t like doing things the hard way. I know I don’t.
While some people think that being lazy is a bad thing, I think that laziness can be a great thing in certain cases.
When it comes to doing repetitive tasks, I prefer to automate them as much as I possibly can. Instead of spending 15 minutes every day doing the same thing, for example, I’d rather spend an hour or two to write some scripts to do it for me. Most experienced system admins and network engineers that I know are the same way.
Fortunately, Cisco IOS affords us a number of opportunities to be
The most used “shortcut” in the CLI is tab completion. You may already be familiar with tab completion if you use Linux or UNIX systems.
In the Cisco IOS CLI, you can use the <TAB> key to save you lots of typing. When entering a command into the CLI, simply press the <TAB> key and IOS will “type” the rest of the keyword in for you (assuming that you have entered enough of it for IOS to determine which command you’re referring to).
Let’s try this out with one of the basic IOS commands we’ve already learned, show running-configuration. That’s a long command to type in, especially when you consider how much you’ll be using it. Let’s be
Enter privileged exec mode, type show run into the CLI, then press the <TAB> key. Your screen should look similar to the following:
Router# show run Router# show running-config
IOS completed the rest of the keyword for us. You can use tab completion for any commands or keywords anywhere in the CLI. Let’s try it again with another command we’ve already learned, show version.
Type show ver and then press the <TAB> key. Once again, IOS will complete the command for us:
Router# show ver Router# show version
After IOS completes the command, go ahead and press <ENTER> to execute the command. As you can see, the effect is the same as if we have manually typed in the complete show version command.
Router# show ver Router# show version Cisco IOS Software, Linux Software (I86BI_LINUX-ADVENTERPRISEK9_IVS-M), Version 15.1(4)M, DEVELOPMENT TEST SOFTWARE Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2011 by Cisco Systems, Inc. Compiled Fri 25-Mar-11 16:59 by prod_rel_team ROM: Bootstrap program is Linux ... Linux Unix (Intel-x86) processor with 140260K bytes of memory. Processor board ID 2048042 8 Ethernet interfaces 8 Serial interfaces 64K bytes of NVRAM. Configuration register is 0x0 Router#
As you can tell, tab completion is a great way to save time and keystrokes when working in the CLI.
Abbreviate Your Commands
Another great timesaver when working on the CLI is the ability to abbreviate commands. IOS allows us to abbreviate commands we enter as long as we enter enough for IOS to determine which command we are referring to.
Both parts of the show running-configuration command that we often use can be abbreviated, for example. We can abbreviate show as sh and we can abbreviate running-configuration all the way down to run.
Router# sh run Building configuration... Current configuration : 1722 bytes ! ! Last configuration change at 14:55:47 EST Tue Sep 6 2011 version 15.1 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ...
Because show is the only command that begins with sh, IOS is able to determine which command we want it to execute. If you abbreviate too much, however, you’ll get that ambiguous command error message we saw in Cisco IOS Error Messages.
Router# s run % Ambiguous command: " s run"
Tab completion and abbreviations aren’t the only shortcuts available in the CLI. IOS also provides a number of “hot keys” that we can use to make our life easier.
Up and Down Arrows
When working in the CLI, you can use the up and down arrows to scroll through the list of commands that you have already entered.
If you’re following along, go ahead and hit the up arrow key. You should see that the CLI is now displaying the show version command that we just ran. If you continue to scroll up, you’ll see the show running-configuration command that we ran earlier. Press the down arrow key and you’ll be returned to the show version command.
Using the arrow keys is a great way to save time when you need to execute a command that you’ve already ran. The CTRL-P and CTRL-N keys also serve the same purpose as the up and down arrows.
Pressing CTRL-C will “interrupt” the command you are currently entering and return you to configuration mode. This is handy if you are entering a long command and then decide that you don’t wish to execute it. Instead of using the backspace key to delete the command you’ve been typing, just press CTRL-C to cancel it.
To illustrate, let’s say that you were in the process of entering in the show ip ospf database command but, at the last minute, you decide not to.
Router# show ip ospf datab
Simply press CTRL-C to cancel the command and return to the prompt.
NOTE: In the following example, ^C depicts the point at which I pressed CTRL-C.
Router# show ip ospf datab^C Router#
The CTRL-Z is useful when you are several levels into the configuration hierarchy and you wish to return to global configuration mode.
In The Cisco CLI: IOS Modes we learned how to that the exit command will return us to the previous configuration mode and the end command will return us to global configuration mode.
CTRL-Z is a shortcut for the end and will also return us to global configuration mode, as seen here:
Router(config-if)# ^Z Router#
NOTE: ^Z depicts the pressing of CTRL-Z.
Pressing CTRL-R will cause IOS to “redraw” the current command that you are typing. This is handy as sometimes output from the CLI will interfere with what you are typing and leave you confused, wondering where exactly you left off.
In this example, I will return to global configuration mode and then begin typing in the show running-configuration command. You can see that output from the router interrupts the command I was typing in. Pressing CTRL-R causes IOS to refresh the line.
Router(config-if)# end Router# show ru*Sep 6 19:55:47.722: %SYS-5-CONFIG_I: Configured from console by console
While the output does not affect the command you’re typing in, it can make it confusing. Simply press CTRL-R and IOS will refresh the line and you can continue typing in your command.
Router# show ru*Sep 6 19:55:47.722: %SYS-5-CONFIG_I: Configured from console by console^R Router# show ru
Later, you’ll learn how to use the ping and traceroute commands for troubleshooting and verification. Sometimes, though, we want to interrupt or “cancel” the execution of these commands and we can do that by pressing CTRL-SHIFT-6.
In this example, I am running a traceroute to ftp-sj.cisco.com. You can see that, after a certain point, no useful information is returned due to Cisco blocking this traffic with their firewalls. We can sit and wait for it to eventually finish if we want to, but there’s really no point. Instead, we can simply press CTRL-SHIFT-6 to cancel the traceroute.
Router# traceroute ftp-sj.cisco.com Translating "ftp-sj.cisco.com"...domain server (192.0.2.1) [OK] Type escape sequence to abort. Tracing the route to download-rcdn1.cisco.com (188.8.131.52) 1 router.lab.evilrouters.net (192.0.2.1) 8 msec 4 msec 4 msec 2 border2-col-GE-0-0-802.tls.net (184.108.40.206) 48 msec 52 msec 56 msec 3 220.127.116.11 68 msec 48 msec * 4 * cr81.ipsin.ip.att.net (18.104.22.168) 56 msec 72 msec 5 cr1.cgcil.ip.att.net (22.214.171.124) 56 msec 64 msec 56 msec 6 cr2.cgcil.ip.att.net (126.96.36.199) 56 msec 88 msec 92 msec 7 cr2.sl9mo.ip.att.net (188.8.131.52) 72 msec 60 msec 56 msec 8 cr2.kc9mo.ip.att.net (184.108.40.206) 60 msec 56 msec 60 msec 9 cr1.dlstx.ip.att.net (220.127.116.11) 80 msec 88 msec 72 msec 10 cr83.dlstx.ip.att.net (18.104.22.168) 56 msec 60 msec 68 msec 11 gar28.dlstx.ip.att.net (22.214.171.124) 52 msec 56 msec 52 msec 12 126.96.36.199 72 msec 80 msec 92 msec 13 rcdn9-cd2-dmzbb-gw2-ten1-1.cisco.com (188.8.131.52) 80 msec 68 msec 56 msec 14 rcdn9-cd2-dmzdcc-gw2-por-2.cisco.com (184.108.40.206) 64 msec 56 msec 60 msec 15 rcdn9-16a-dcz05n-gw2-ten5-5.cisco.com (220.127.116.11) 64 msec 64 msec 60 msec 16 * * * 17 * * * 18 * * * 19 * * Router#
NOTE: CTRL-SHIFT-6 is the “escape sequence” mention on the fourth line of the output.
As you can see, using these shortcuts can save us a lot of time and keystrokes when working in the CLI. For clarity, I’ll usually write out the full commands in these articles but, in practice, I use the shortcuts and abbreviations whenever possible.