Yes yes I haven’t posted in anything in a long time, but hey! I’m back now!
This post will go over some of the handy tips and tricks in the Cisco CLI.
Moving Around
SHORTCUT | DESCRIPTION |
---|---|
Ctrl+A | Move cursor to the beginning for the line |
Ctrl+E | Move cursor to the end of the line |
Ctrl+F | Move cursor forward one character |
Ctrl+B | Move cursor backward |
Esc+F | Moves forward one word |
Esc+B | Moves backwards one word |
Ctrl+P | Previous command |
Ctrl+N | Next command |
SHORTCUT | DESCRIPTION | |
---|---|---|
Ctrl+W | Delete the word to the left from the cursor | |
Ctrl+U | Delete the whole line | |
Ctrl+T | Swap or transpose the current character with the one before it | |
Ctrl+K | Erase characters from the cursor to end of the line | |
Ctrl+X | Erase characters from the cursor to beginning of the line | |
Esc+D | Delete from Cursor to end of word | |
Delete | Removes the character to the right of the cursor | |
Backspace | Removes the character to the left of the cursor | |
Up Arrow | Allows you to scroll forward through previous commands | |
Down Arrow | Allows you to scroll backwards through previous commands |
SHORTCUT | DESCRIPTION |
---|---|
Ctrl+L | Reprint the line |
Ctrl+R | Refresh |
Tab | Command autocomplete |
Ctrl+C | Exit. Exit from config mode |
Ctrl+Z | Apply the command line and exit from config mode ie. return to privileged EXEC mode. |
Ctrl+Shift+6 (X) | CTRL-SHIFT-6 is one action, the X is the second action |
SHORTCUT | DESCRIPTION |
---|---|
Esc, C | Makes the letter at the cursor uppercase. |
Esc, L | Changes the word at the cursor to lowercase |
Esc, U | Makes letters from the cursor to the end of the word uppercase. |
SHORTCUT | DESCRIPTION | |
---|---|---|
The buffer stores the last ten items that have been deleted using Ctrl-K, Ctrl-U, or Ctrl-X | ||
Ctrl-Y | Paste the most recent entry in the delete buffer | |
Esc-Y | Paste the Previous entry in the history buffer |
Showing Run who’s boss
You can control the output of show run in a few different ways in order to to help you be more efficient when looking through your configuration.
If you want to look at the configuration on a particular interface, you can use the show run interface <#>
R1#show run interface l0 Building configuration...
Current configuration : 99 bytes ! interface Loopback0 ip address 150.1.1.1 255.255.255.255 ipv6 address 2001:150:1:1::1/128
You can also display line numbers with the show run linenum command, this is handy if you want to help guide someone to a certain part of the config.
R1#show run linenum Building configuration...
Current configuration : 2435 bytes 1 : ! 2 : ! Last configuration change at 06:47:30 UTC Tue Nov 17 2015 3 : ! 4 : version 15.5 5 : no service timestamps debug uptime 6 : no service timestamps log uptime 7 : no platform punt-keepalive disable-kernel-core 8 : platform console serial 9 : ! 10 : hostname R1 11 : ! 12 : boot-start-marker 13 : boot-end-marker 14 : !
Cisco automatically hides default config values from show run but you can override this behavior with show run all this is a good way of learning what the default settings are for your device.
R1#show run all Building configuration...
Current configuration with default configurations exposed : 225746 bytes ! ! Last configuration change at 06:47:30 UTC Tue Nov 17 2015 ! version 15.5 downward-compatible-config 15.5 no service log backtrace no service config no service exec-callback no service nagle service slave-log no service slave-coredump no service pad to-xot no service pad from-xot no service pad cmns service pad
You can also search for configuration by pressing the / key when the show run is displaying –more
R1#show run Building configuration...
Current configuration : 2435 bytes ! ! --More--
/router filtering... router ospf 1 auto-cost reference-bandwidth 1000 area 1 virtual-link 150.1.6.6 network 150.1.1.0 0.0.0.255 area 0 network 155.1.0.0 0.0.0.255 area 0 network 155.1.13.0 0.0.0.255 area 4 network 155.1.146.0 0.0.0.255 area 1
Pipe Dreams
One of the most powerful tools you have for controlling output is pipe commands (|) these allow you to use regular expressions to filter show command output to exactly what you need.
The exact pipe commands you get depends on your platform but the most commonly used is:
Begin: Starts the output at the first match found.
R1#show run | begin router router ospf 1 auto-cost reference-bandwidth 1000 area 1 virtual-link 150.1.6.6 network 150.1.1.0 0.0.0.255 area 0 network 155.1.0.0 0.0.0.255 area 0 network 155.1.13.0 0.0.0.255 area 4 network 155.1.146.0 0.0.0.255 area 1 ! ! virtual-service csr_mgmt ! ip forward-protocol nd
Include: Display only the line that matches the expression
R1#show ip route | in 150 150.1.0.0/32 is subnetted, 11 subnets C 150.1.1.1 is directly connected, Loopback0 O 150.1.2.2 [110/10003] via 155.1.146.4, 05:45:01, GigabitEthernet1.146 O 150.1.3.3 [110/10003] via 155.1.146.4, 05:45:01, GigabitEthernet1.146 O 150.1.4.4 [110/2] via 155.1.146.4, 05:45:01, GigabitEthernet1.146 O 150.1.5.5 [110/3] via 155.1.146.4, 05:45:01, GigabitEthernet1.146 O 150.1.6.6 [110/2] via 155.1.146.6, 1d02h, GigabitEthernet1.146 O IA 150.1.7.7 [110/3] via 155.1.146.6, 1d02h, GigabitEthernet1.146 O IA 150.1.8.8 [110/4] via 155.1.146.4, 05:45:11, GigabitEthernet1.146 O IA 150.1.9.9 [110/4] via 155.1.146.6, 1d02h, GigabitEthernet1.146 O IA 150.1.10.10 [110/5] via 155.1.146.4, 05:45:11, GigabitEthernet1.146 O IA 150.1.22.22 [110/10003] via 155.1.146.4, 1d01h, GigabitEthernet1.146
Exclude: Display everything but the matching line.
R1#show ip int br | exclude unassign Interface IP-Address OK? Method Status Protocol GigabitEthernet1.13 155.1.13.1 YES manual up up GigabitEthernet1.100 169.254.100.1 YES manual up up GigabitEthernet1.146 155.1.146.1 YES manual up up Loopback0 150.1.1.1 YES manual up up Tunnel0 155.1.0.1 YES manual up up
Section: Display the matching line and any sub-configuration beneath it.
R1#show run | section line line con 0 exec-timeout 0 0 privilege level 15 logging synchronous stopbits 1 line vty 0 4 privilege level 15 no login
You can also use Regular Expressions to get more fancy with your matching.
R1#show ip route | in (\.5\.)+ O 150.1.5.5 [110/3] via 155.1.146.4, 05:49:10, GigabitEthernet1.146 O IA 155.1.5.0/24 [110/3] via 155.1.146.4, 1d02h, GigabitEthernet1.146
You can also do a logical OR by adding a second pipe
R4(config-router)#do sh ip route | in 110|120 R 11.11.11.11 [120/1] via 155.1.146.1, 00:00:16, GigabitEthernet1.146 O 150.1.1.1 [110/2] via 155.1.146.1, 15:14:44, GigabitEthernet1.146 O 150.1.2.2 [110/10002] via 155.1.45.5, 1d15h, GigabitEthernet1.45 O 150.1.3.3 [110/10002] via 155.1.45.5, 1d15h, GigabitEthernet1.45 O 150.1.5.5 [110/2] via 155.1.45.5, 1d15h, GigabitEthernet1.45 O 150.1.6.6 [110/2] via 155.1.146.6, 1d16h, GigabitEthernet1.146 O IA 150.1.7.7 [110/3] via 155.1.146.6, 1d11h, GigabitEthernet1.146
You can use as many ORs as you need to get the exact output you want
R1# show int | in up|MTU|address GigabitEthernet1 is up, line protocol is up Hardware is CSR vNIC, address is fa16.3e3a.d2a4 (bia fa16.3e3a.d2a4) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, Full Duplex, 1000Mbps, link type is force-up, media type is RJ45 output flow-control is unsupported, input flow-control is unsupported GigabitEthernet1.13 is up, line protocol is up Hardware is CSR vNIC, address is fa16.3e3a.d2a4 (bia fa16.3e3a.d2a4) Internet address is 155.1.13.1/24 MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
It is also possible to do a logical AND with your show commands by chaining together .* in between your keywords
R4(config-if)#do sh ip int br | include (.*up.*down) Tunnel1 unassigned YES unset up down
Finally we can use IOS.sh to get some grep love into the mix!
R1#terminal shell
Now we can use linux style grep commands
R1#show ip route | grep (150) | grep -v (\.10\.) 150.1.0.0/32 is subnetted, 11 subnets C 150.1.1.1 is directly connected, Loopback0 R1#show ip route | grep (150) | grep (10003) O 150.1.2.2 [110/10003] via 155.1.146.4, 15:51:41, GigabitEthernet1.146 O 150.1.3.3 [110/10003] via 155.1.146.4, 15:51:41, GigabitEthernet1.146 O IA 150.1.22.22 [110/10003] via 155.1.146.4, 1d11h, GigabitEthernet1.146 R1#show ip route | grep (150) | grep -v (10003) 150.1.0.0/32 is subnetted, 11 subnets C 150.1.1.1 is directly connected, Loopback0 O 150.1.4.4 [110/2] via 155.1.146.4, 15:51:57, GigabitEthernet1.146 O 150.1.5.5 [110/3] via 155.1.146.4, 15:51:57, GigabitEthernet1.146 O 150.1.6.6 [110/2] via 155.1.146.6, 1d12h, GigabitEthernet1.146 O IA 150.1.7.7 [110/3] via 155.1.146.6, 1d12h, GigabitEthernet1.146 O IA 150.1.8.8 [110/4] via 155.1.146.4, 15:52:07, GigabitEthernet1.146 O IA 150.1.9.9 [110/4] via 155.1.146.6, 1d12h, GigabitEthernet1.146 O IA 150.1.10.10 [110/5] via 155.1.146.4, 15:52:07, GigabitEthernet1.146