Wednesday, February 15, 2006

You thought you knew everything about cmd.exe!

Last month, Michael Kaplan explained that after all this time, he thought he knew everything there was to know about the MessageBox Win32 API yet managed to find something new to him (and to me as well BTW ;-).

And after all this time, I thought I knew everything one might want to know about the good old command prompt, cmd.exe:

Of course I know that Windows XP's command prompt accepts document names in addition to exe command names. e.g.: you can type services.msc to open the Services applet. Or you can simply type the name of a Word document to open it.
(I say XP's command prompt because IIRC it wasn't the case in previous versions).

I knew about how to enable auto-complete of filenames in Windows 2000 before it became a default setting in XP.

OK, for sure I'm no expert in batch files but at least I know my limits in the area.

A (not so) hidden command history list

But last week, I discovered that I'm not as knowledgeable as I thought. Will you believe the unbearable? Yes, a cmd.exe feature I had never seen before. I was switching between Visual Studio and a couple of command prompts. At some moment, I hit F7 to recompile while the focus was still in one of the command prompts.



Ho! F7 triggers a pop-up window with the command history. Boy, I just can't believe how I have been able to never see that before! The funny thing is that I talked to a couple other developers about it and none of them knew about F7 either.

Auto-complete recent commands

OK, let's try the other function keys to see if there's another handy goodie hiding in there. F8 is the only other interesting one I found: type the start of a command, then F8 repeatedly: it will auto-complete your command with the ones in your command history.

Console window title



While on the subject of less known features, the title command is another interesting one: it sets the title of the console window. This is particularly interesting when you keep several command prompts opened simultaneously : You can immediately identify each one in the task bar instead of having to go through each of these anonymous "c:\windows\sys..." task bar buttons.



And if you are interested in Internet Explorer keyboard shortcuts, Jeff Atwood recently posted a summary.

30 Comments:

At 12:53 AM, Anonymous Daniel Lohmann said...

He, he, the good old cmd.exe is a surprising tool and it brings all its whistles and bells only step-by-step to the public. Almost nobody knows that all these things even worked in Windows NT 3.1! Yes, tab completion, history lists and so on have been available since the very first day of Windows NT.

I'd just like to add some more more or less known secrets:

Fn keystrokes:
-Serge already mentioned F7 to get a command history list. Every commands in this history is numbered. By pressing F9+[number] you can execute one of them again without having to go through the list.

-F4 opens a box where you can enter a character. The part of the command line right of the curser is deleted up to this caracter.

-F2 works similar, but simply jumps to the entered character. (The function describes itself as "copy" which is a bit confusing)

-F6 prints out an EoF character (Ctrl+Z). This can be used to terminate a console window redirection (e.g. started with "type con > newfile" to enter a few lines into a text file)

-F5 and F8 can be used to walk through the command history. (Not that exciting - unless you find yourself in front of a keyboard without cursor keys :-)

Some more "meta"-commands:
Besides the "title" command many other are available to change the appearance of a console window. Most usful are (IMHO):

-the "color" command. I usually have a cmd.exe shell running as Administrator on my desktop. A simple "color cf" paints it red, preventing me from accidentally using it for non-Admin tasks.

- the "mode" command. Can be used to change the size of the console window without having to go through the menus. Example: "mode con cols=100 lines=60"

AutoRun:
It is possible to execute some commands whenever a new console window is started. CMD.exe looks under "[HKLM|HKCU]\Software\Microsoft\Command Processor" for a string value named "AutoRun" and executes whatever it finds there. This is particulary useful to distinguish different user accounts. I put, for instance, the "color cf" into the AutoRun string for user Administrator. Another idea is to put a "title %USERNAME%" there.

And AutoRun, at least, is really a new XP feature :-)

Have fun!

Daniel

 
At 11:53 PM, Anonymous Serge said...

Hey Daniel!
Glad to 'see' you here.

Wow! Do you mind if I call you Danielpedia :-)

 
At 9:53 PM, Anonymous Anonymous said...

Hi,

The F7 was really good one

Patricia Govezensky

 
At 12:25 AM, Anonymous ofer said...

Great!!!
i want to add another tip (although its works in most windows applications).
when you press ctrl + left/right arrow the curser jumps to the next/previous word.
when you press ctrl + home/end all the charecters from the curser to the begining/end of the row are deleted.

 
At 8:59 AM, Anonymous Serge said...

Ofer,

That's a great tip. Of course people know these shortcuts in regular Windows apps. But I bet most never realized it works in consoles as well ;-)

The thing I'd love with Ctrl+left/right would be that it stops at each backslash as well. It would make it easier to manipulate paths.

 
At 6:19 PM, Anonymous Peter Louwen said...

All this is old news for
anyone who has ever used Doskey (which was available
in DOS since 1800 or so).

The F6 trick dates back even further.

If only they made function key redefinition a la ANSI.SYS available again...

 
At 6:53 PM, Blogger Serge Wautier said...

Oh really? I thought I missed it during 10 years. And you're telling me it's been at my fingertips for 20 years... Ouch! I'm even more ignorant than I thought :-)

 
At 11:18 AM, Anonymous Anonymous said...

Hi,

I'm in the opposite situation... After executing a command, the history list pop up and there is nothing else i can do than re executing the same command or closing de whole console... The problem occure on one of our server and is very annoying. hitting F7 doesn't make the history list disepear.

Any solution?

Nico

 
At 10:50 PM, Anonymous Anonymous said...

miley cyrus nude [url=http://crystal-liu.com/forums/index.php?showuser=1113]miley cyrus nude[/url] miley cyrus sex tape [url=http://forum.ondertitel.com/index.php?showuser=74503]miley cyrus sex tape[/url] miley cyrus nude [url=http://stabilo.forumsunlimited.com/index.php?showuser=799]miley cyrus nude[/url] miley cyrus nude [url=http://ragga-jungle.com/user/15036-vebsterd]miley cyrus nude[/url] kim kardashian nude [url=http://forums.quark.com/members/vebsterd.aspx]kim kardashian nude[/url]

 
At 2:18 PM, Anonymous Anonymous said...

Buy Endress & Hauser models at up to 20% discount from list price

Endress+Hauser is a leading supplier of measuring instruments and automation solutions for the industrial process engineering industry.

Endress+Hauser is recognized as a leading supplier of industrial measurement and automation equipment, providing services and solutions for industrial processes all over the world. Endress+Hauser offer comprehensive process solutions for flow, level, pressure, analysis, temperature, recording and digital communications across a wide range of industries, optimizing processes in regards to economic efficiency, safety and environmental protection.

As major stockists of many Endress and Hauser level instruments, We [url=http://www.endress.org.ua]official distributor Endress+Hauser in Ukraine[/url], can offer a range of Endress & Hauser models at up to 20% discount from list price - prices usually only available when buying in bulk.

Feel free to contact us.

 
At 5:42 PM, Anonymous Anonymous said...

married asian personals [url=http://loveepicentre.com/]dating data[/url] israel dating http://loveepicentre.com/ under age dating

 
At 6:28 PM, Anonymous Anonymous said...

cougar wmen dating [url=http://loveepicentre.com/]best male escorts gt first online dating site[/url] dating chat http://loveepicentre.com/ senior christian dating help

 
At 8:58 PM, Anonymous cheap viagra said...

hello buddy amazing post about You thought you knew everything about cmd.exe! this information is very useful!!

 
At 10:38 PM, Anonymous propecia online said...

He vanished for a bit, but, god, what a great post. I'm so glad he didn't stay away.

 
At 12:42 AM, Anonymous Anonymous said...

laptop batteries [url=http://www.hqlaptopbatteries.com/-c303xmib-laptopbatterymodel1088.html]laptop battery[/url] laptop accessories http://www.hqlaptopbatteries.com/-5503wxci-laptopbatterymodel1116.html Acer laptop battery
IBM laptop battery [url=http://www.hqlaptopbatteries.com/-2675dvd-laptopbatterymodel65.html]dell laptop[/url] laptop comparison http://www.hqlaptopbatteries.com/battery-3002wlmi-batterytype1.html Laptops & notebooks
laptop batteries reviews [url=http://www.hqlaptopbatteries.com/-2510cds-laptopbatterymodel134.html]compare prices laptop batteries[/url] compare prices laptop batteries http://www.hqlaptopbatteries.com/-3681wxci-laptopbatterymodel1172.html Alienware Laptop

 
At 10:01 PM, Anonymous generic viagra said...

hello friend great post about You thought you knew everything about cmd.exe! thanks

 
At 10:11 PM, Anonymous Anonymous said...

hola

 
At 4:27 AM, Anonymous Anonymous said...

upbound medical for palm [url=http://usadrugstoretoday.com/products/oxytrol.htm]oxytrol[/url] breast lift topeka http://usadrugstoretoday.com/categories/arreter-de-fumer.htm uk suplimental health insurance http://usadrugstoretoday.com/categories/antidepressivo---anti-ansia.htm
danville schools grants for drug testing [url=http://usadrugstoretoday.com/categories/magen-darm.htm]magen darm[/url] lose weght and vegetarian diet [url=http://usadrugstoretoday.com/products/lopid.htm]northern wv rural health education center[/url]

 
At 7:19 AM, Anonymous Anonymous said...

health benefits federal term appointments [url=http://usadrugstoretoday.com/bestsellers.htm]Pharmacy bestsellers[/url] hot chick fucked while sleeping http://usadrugstoretoday.com/products/zoloft.htm limp penis photos http://usadrugstoretoday.com/products/vitaliq.htm
airborne medicine website [url=http://usadrugstoretoday.com/products/femara.htm]femara[/url] iowa weight loss programs [url=http://usadrugstoretoday.com/products/biaxin.htm]analyzers blood gas[/url]

 
At 2:36 AM, Anonymous Anonymous said...

Seriously! Wanna good joke? What did one wall say to the other wall? Meet you at the corner. vigera
patent

 
At 6:47 AM, Anonymous Anonymous said...

i have a brown spot near my penis [url=http://usadrugstoretoday.com/products/valtrex.htm]valtrex[/url] tooth whitening san francisco htm http://usadrugstoretoday.com/products/strontium-bone-maker.htm causes of sure vaginal area http://usadrugstoretoday.com/products/rogaine-2-.htm
dental uhc dmo [url=http://usadrugstoretoday.com/categories/men-s-health.htm]men s health[/url] chicks and muscle cars [url=http://usadrugstoretoday.com/products/strontium-bone-maker.htm]incidence prostate cancer[/url]

 
At 3:00 PM, Anonymous Anonymous said...

Hotel reservations

 
At 4:19 PM, Anonymous Anonymous said...

the brazilian diet pill [url=http://usadrugstoretoday.com/categories/herz-kreislauf.htm]herz kreislauf[/url] how common is heart disease http://usadrugstoretoday.com/products/detrol.htm health benefits of pomegranet juice http://usadrugstoretoday.com/products/sumycin.htm
suny and upstate medical center [url=http://usadrugstoretoday.com/products/diovan.htm]diovan[/url] individual health care insurance [url=http://usadrugstoretoday.com/products/lioresal.htm]lehar la vedova allegra tace il labbro sheet[/url]

 
At 7:19 PM, Anonymous Anonymous said...

health pharmacy drugs and medications s sildenafil [url=http://usadrugstoretoday.com/products/lopid.htm]lopid[/url] gold canyon medical center san antonio http://usadrugstoretoday.com/products/exelon.htm npi for cvs pharmacy http://usadrugstoretoday.com/products/zebeta.htm
swollen breast and early pregnancy [url=http://usadrugstoretoday.com/products/kamagra-oral-jelly.htm]kamagra oral jelly[/url] bland diet gov [url=http://usadrugstoretoday.com/products/toprol-xl.htm]how to talk to people with bipolar disorder[/url]

 
At 7:39 PM, Anonymous Anonymous said...

muscle hustle [url=http://usadrugstoretoday.com/products/luvox.htm]luvox[/url] cancer markers in blood http://usadrugstoretoday.com/products/micardis.htm tea pot dome affair http://usadrugstoretoday.com/products/buspar.htm
cold blood tabs [url=http://usadrugstoretoday.com/products/effexor-xr.htm]effexor xr[/url] sjogrens syndrome in traditional chinese medicine [url=http://usadrugstoretoday.com/categories/anti-diabetici.htm]cut off penis youtube[/url]

 
At 10:26 PM, Anonymous Anonymous said...

supplements vitamins for prescription drugs [url=http://usadrugstoretoday.com/products/flonase.htm]flonase[/url] histamines fda tuna compliant http://usadrugstoretoday.com/products/rumalaya.htm academic stress and college students http://usadrugstoretoday.com/products/xplode--stamina--energy-and-sex-enhancer-.htm
environmental and health impacts of ships [url=http://usadrugstoretoday.com/products/hyaluronic-acid.htm]hyaluronic acid[/url] missouri law health clubs [url=http://usadrugstoretoday.com/products/weight-loss.htm]zantac reactions[/url]

 
At 8:36 AM, Anonymous Anonymous said...

gum [url=http://usadrugstoretoday.com/categories/general-health.htm]general health[/url] angelina jolie eating disorder http://usadrugstoretoday.com/products/cialis-soft-tabs.htm heshouwu pills http://usadrugstoretoday.com/products/doxazosin.htm
nice guidance anxiety [url=http://usadrugstoretoday.com/products/aldactone.htm]aldactone[/url] mineral wells newspaper [url=http://usadrugstoretoday.com/products/terramycin.htm]shyness depression social anxiety[/url]

 
At 4:45 AM, Anonymous Anonymous said...

identify black vitamin spe soft [url=http://usadrugstoretoday.com/products/clomid.htm]clomid[/url] depression carnival glass http://usadrugstoretoday.com/products/arimidex.htm horrizon new jersey plus health insurance http://usadrugstoretoday.com/products/pro-erex.htm
wisconsin medicaid dental managed care capitation [url=http://usadrugstoretoday.com/products/citalopram.htm]citalopram[/url] good samaritan sued county for mental stress after an accident [url=http://usadrugstoretoday.com/categories/anti-hongos.htm]susan g komen breast cancer walk[/url]

 
At 7:29 AM, Anonymous Anonymous said...

pale from depression [url=http://usadrugstoretoday.com/products/augmentin.htm]augmentin[/url] the future of health in society http://usadrugstoretoday.com/products/zovirax.htm hysteria conversion disorder http://usadrugstoretoday.com/products/digoxin.htm
endocrine medical associates [url=http://usadrugstoretoday.com/products/pulmicort.htm]pulmicort[/url] aspirin absorption [url=http://usadrugstoretoday.com/products/premarin.htm]hair loss and vitamin deficiency[/url]

 
At 7:48 AM, Anonymous Anonymous said...

allergic teen free porn pictures [url=http://usadrugstoretoday.com/products/ilosone.htm]ilosone[/url] great depression lesson plans http://usadrugstoretoday.com/products/zebeta.htm breast augmentation and autoimmune disorders http://usadrugstoretoday.com/catalogue/1.htm
first nations mental health [url=http://usadrugstoretoday.com/products/tulasi.htm]tulasi[/url] mineral turpentine vs turpentine [url=http://usadrugstoretoday.com/products/luvox.htm]pilates weight loss success[/url]

 

Post a Comment

<< Home