The "do" command
Objective
To understand the do command and its functionality within Cisco IOS.
Topology
We will only be using one router for this tutorial.
R1The Problem
It's annoying having to exit from config mode to exec mode every time you want to run a show command. Or from interface config mode you need to get all the way to exec mode to do a show command.
For example, if I want to configure an interface and at the same time check the configuration, I need to do this:
R1(config)#interface gi0/0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#exit
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
Embedded-Service-Engine0/0 unassigned YES unset administratively down down
GigabitEthernet0/0 10.1.1.1 YES manual down down
GigabitEthernet0/1 unassigned YES unset administratively down down
R1#As you can see, I have to type exit twice to get to exec mode and then I can run the show ip interface brief command.
The Solution
The do command allows you to execute exec-level commands while in configuration mode. This means you don't have to exit out of configuration mode to run show commands.
Here's the same scenario using the do command:
R1(config)#interface gi0/0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#do show ip interface brief
Interface IP-Address OK? Method Status Protocol
Embedded-Service-Engine0/0 unassigned YES unset administratively down down
GigabitEthernet0/0 10.1.1.1 YES manual down down
GigabitEthernet0/1 unassigned YES unset administratively down down
R1(config-if)#As you can see, I'm still in interface configuration mode, but I was able to execute the show ip interface brief command by prefixing it with do.
Other Examples
The do command works with any exec-level command. Here are some common examples:
R1(config)#do show run
R1(config)#do show ip route
R1(config)#do ping 8.8.8.8
R1(config)#do copy run start
R1(config-if)#do show interfaces
R1(config-router)#do show ip protocolsImportant Notes
- The
docommand only works with exec-level commands (commands available at the # prompt) - It works from any configuration mode (global config, interface config, router config, etc.)
- After executing the command, you remain in the same configuration mode
- This is a huge time-saver during configuration tasks
Conclusion
The do command is one of those simple features that makes your life much easier when working with Cisco devices. Instead of constantly exiting configuration modes to run show commands, you can stay in configuration mode and simply prefix your exec commands with do.