Command Line Tricks for Cisco Geeks

I know most of you probably know a lot of the tricks on this list, but you might find a thing or two that you never knew existed. These tricks can save you seconds and a lot frustration when you trying to hammer out a command. Although, Cisco seems to be moving away from CLI in some of their products, like the ASA, in fact there are things you can’t do on the CLI that you can do in the GUI, that is just wrong.

But, anyway enough ranting, here is my list of tricks. First up keyboard shortcuts.

Keyboard Shortcuts

Shortcut Function
CTRL-R Reprint line, useful to recover from a trashed prompt from console messages
CTRL-A Move cursor to beginning of line
CTRL-E Move cursor to end of line
Esc-B Move backwards one word
Esc-F Move forward one word
CTRL-W Deletes the word cursor is under
CTRL-U Deletes the entire line
CTRL-Shift-6 Terminate operation (ping, traceroute, etc)
CTRL-Shift-6,X Suspends session
CTRL-Z Exits configuration mode, returning you to privileged EXEC mode
TAB Completes a partial command
CTRL-P Rotate backward through command history
CTRL-N Rotate forward through command history

Output Parsing (Where is grep?!?)

Next, there will be times when you have to comb through hundreds of lines of command output, just like on the Unix CLI, we have tools to aid us. All of us know and love grep and probably use it every day, but in the Cisco world we have to use include, there aren’t any options, it just rips out lines that include the regular expression you provide. Regular Expression? Yes, just like his Unix cousin, you can match against regexp.

Example. I want to obtain a list of interfaces that are up both at the physical and data link layers.

SC#show ip int | include up.*up

Another neat trick is to get a list of interfaces with their MTU and bandwidth.

SC#show interface | include protocol|BW
ATM0/0 is administratively down, line protocol is down
  MTU 4470 bytes, sub MTU 4470, BW 1024 Kbit, DLY 500 usec,
FastEthernet0/0 is up, line protocol is up
  MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
Serial0/0 is administratively down, line protocol is down
  MTU 1500 bytes, BW 1544 Kbit, DLY 20000 usec,
FastEthernet0/1 is up, line protocol is down
  MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,

You can also do the reverse of the previous trick with exclude. Useful if you want to send the configuration to a colleague, use the exclude command to remove all username / password / secret keys from a configuration output.

SC#show running-config | exclude enable|username
Building configuration...

Current configuration : 1815 bytes
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
service password-encryption
hostname SC
[cut for brevity]

It’s a common task to want a dump a certain part of a configuration, for me I like to dump the route protocol configuration or a VPN configuration. You can use the section keyword to output just a section of configuration.

SC#show running | section router
router rip

If you are wondering, this works on CLI output too. You can also use the two previous tricks in combination, so you could include a section. So, if I want to include just the FastEthernet interface sections from the command show interfaces, you can do just that.

SC#show interfaces | section include FastEthernet
FastEthernet0/0 is up, line protocol is up
  Hardware is Gt96k FE, address is 0013.60f6.5120 (bia 0013.60f6.5120)
  Internet address is
[cut for brevity]


There are a few other obscure commands, like tee and redirect. tee works like the Unix CLI version, displays and redirects to a URL, which can be a local file. Redirect CLI output to a URL, not entirely sure how people use these commands, I never really made any use of them. I have an idea for redirect, just not sure it’s feasible.

If you know a cool trick or shortcut, leave a comment and I will add it to the post.

Feb 21st, 2011 • Posted in IOS
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>