Basic Alias Commands
There are plenty of articles and posts around showing you how to use alias commands, but I never see them being used to their full potential. Let’s look at how we can get a bit more than the obvious out of this useful little critter!
We’ll start with some basic aliases we are all probably familiar with. If not, put them in your templates. They are worth the effort!
alias exec srb sh run | beg alias exec srs sh run | sec alias exec sri sh run | incl alias exec siib sh ip int brief alias exec srint sh run interface
These give you great shortcuts to common “show” commands and are invaluable, especially in a CCIE lab setting.
Let’s Get Clever
Now, we all probably use the do command to ‘do’ a show command from within config mode or interface config mode…something like:
R1(config)#do sh ip int brief
You can do the same with your aliases:
R1(config)#do srs alias
I don’t know about anyone else, but I’m forever forgetting to type ‘do’, especially when switching between IOS and ASA devices. Why not put the “show” command in an alias of its own that is applied at the configure level of the cli?
R1(config)#alias configure sh do sh
You can extend this further to any other cli mode you are frequently in:
R1(config)#alias interface sh do sh R1(config)#alias subinterface sh do sh
There are plenty more cli levels that may be more useful if you have a voice or security focus – “alias ?” is worth trawling through…
Now we are in a position where we can ignore the do command at several depths of the cli, much like on an ASA. Useful, but what about our other aliases? Unfortunately, the do show alias isn’t used recursively in other alias commands so the srint we created at the top won’t automatically become do show run interface. That would be nice, but I can see how recursive alias resolution could break things unexpectedly.
That’s not the end of the world though, because with some copy/paste, and finding/replacing, we can replicate our aliases to each level of cli and insert the “do” directly into the alias, like so…
R1(config)#alias exec srb sh run | beg R1(config)#alias exec srs sh run | sec R1(config)#alias exec sri sh run | incl R1(config)#alias exec siib sh ip int brief R1(config)#alias exec srint sh run interface R1(config)# R1(config)#alias configure sh do sh R1(config)#alias configure siib do sh ip int brief R1(config)#alias configure srb do sh run | beg R1(config)#alias configure srs do sh run | sec R1(config)#alias configure sri do sh run | incl R1(config)#alias configure srint do sh run interface R1(config)# R1(config)#alias interface sh do sh R1(config)#alias interface siib do sh ip int brief
…etc., down to all the config sub levels you frequently use. I’ll leave it there. You get the concept by now I’m sure.
Using Alias Cross-Platform
Now we have all our usual aliases directly available at config, interface and subinterface level. So where else can this little command help us out? On the odd occasions where Cisco is not being consistent across platforms (whatever happened to one IOS anyway?), a useful approach is to use the alias command to standardize your shortcuts:
ASA(config)# command-alias exec siib sh interface ip brief ! Did you see what they did there?!?
or replace the standard shortcuts that Cisco somehow forgot:
NX-OS(config)#cli alias name wr copy run start
or just to save your sanity because every OS has different ways of grepping:
IOS-XR(config)#alias shcrc sh int | utility egrep expr "Descri|CRC|line protocol"
Hopefully that’s given you some food for thought. Sometimes amidst all the complicated MPLS/IPv6/IS-IS stuff, it’s nice to take a break and get a really simple tool to help out with the day to day finger trouble! Of course, it might not be so useful if you’re a roaming tech that works on different sites every day, but “alias” is great in an enterprise or SP environment where you can control, or at least influence, the device templates.
(You are using templates aren’t you?)