What are the lesser-known but useful features of the Windows command prompt?
feedback
|
migrated from stackoverflow.com Nov 2 '09 at 19:57
This question came from our site for professional and enthusiast programmers.
closed as not a real question by random♦ Aug 25 '10 at 4:33
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. See the FAQ.
|
If you mean the command prompt, I think the best (not widely known) feature is autocomplete when you press Tab, I find this saves so much time. Another nice feature is pressing F7 to quickly see a list of the last commands typed, however, I still prefer pressing ↑ or ↓. Lastly, since there is no longer a beep command, for when I make scripts, I like including the Alt+Numerical Keyboard 7 symbol which causes a beep. You can test this by doing
(where • is Alt+Numerical Keyboard 7) Also, prior to Windows Vista, They kept the MSDOS editor in there! I love this and you could load it by typing "edit" at the command prompt. Lastly, the prompt command! I can't count the amount of pranks that I used to pull with this!... type the following:
will change the prompt to:
You can get up to a lot of fun here! To find out all symbols, type:
| |||||||||||||
feedback
|
|
CD /D which automatically switches drive as well as directory, e.g.:
No more double commands such as:
To save even more typing you can add an alias (thanks @Phoshi)
Then you can just type:
| |||||||||||
feedback
|
|
For me the CLIP command. Works both with piped or redirected
Copies the output of the dir command to the clipboard. Try it :) Another nice use (see Poshi comment below):
| |||||||||||||
feedback
|
|
Piping, just in general.
would take the output of command 1 as the input of command 2, and the output of command 2 into the input of command 3, then route the output to a text file. Comes in incredibly useful with tools like sed or grep (Just install cygwin already, add the \bin folder to your path and you have (imo) the best *nix tool emulations out there.) Also, using & and && to double-up commands. && can be used as a sort of if statement, too:
will only execute command2 if command1 succeeds. Additionally, you can change the PATHEXT variable to include your favourite scripting language (like .py for python) and write quick CLI apps that you can call like any old executable (like I have sort.py, which intelligently chooses the best sorting algorithm for the given dataset (to a point, of course), and sorts them, and I can call it like Also, and most importantly, HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun lets you specify a command to run when the command window opens. This can be a batch files. Hello .bashrc-style extensions! You can set a custom prompt very easily there, see Want an alias? You'll need doskey, which is built in.
is one I like, to make push and popding easier. The $* expands much like %* in a batch file, allowing true argument support in aliases. Still want to tell me cmd has nothing to offer? It's still no bash, but it's a very usable environment that simply suffers from a slight deficit of inbuilt tools. Some of the inbuilts that ARE there, though, can be used in ways you'd not think of. Got a notes file? How are you planning to append to it, notepad? Silly you.
What does that do, you ask? Why, it allows you to type text, line breaks and all, and then append to a file with control+c. Not bad. | ||||
feedback
|
|
There's a wealth of information about the XP/2000/NT command prompt at SS64.com. This site is one of my favourite resources. | ||||
|
feedback
|
|
Function calls and "goto :eof" returns within batch files:
| ||||
|
feedback
|
|
Pressing F7 will bring up the command history (like This method gives a better overview than using the up/down arrow keys alone. | ||||
|
feedback
|
|
Use the following command to get disk usage. Incl. Bytes free, total number of bytes, available bytes.
Where C: is the letter of the drive. This could be easily calculated in to MB/GB if one wanted, and put into a batch file. For a silent pause in batch files, i tend to use this command here
Where 'n' is the total number of echo requests to send And 'w' is the time to wait in milliseconds. Resize your ShadowStorage ( storage that is used for System Restore )
For more info; use the /? switch :) | ||||
|
feedback
|
Prior to Windows XP, TCP/IP could be uninstalled and reinstalled easily. This would correct problems where the implementation of the protocol became corrupt. In Windows XP, reinstalling TCP/IP was a pain in the rear to do manually, and so in service pack 2, they added the above functionality. | ||||
|
feedback
|
|
Not sure if this is "hidden" feature per se, but did you know you can use the dir command to list the contents of two directories at once?
| ||||
|
feedback
|
|
Here's a script that uses quite a few little used features in order to time another batch file.
It's a bit of a hack but it does work.
| ||||
|
feedback
|
| ||||
|
feedback
|
and
to display the current user and their group memberships, respectively when trouble shooting things like permission related problems or group policy. Double-useful if you are running several command windows as different users using runas or Run As Administrator, and you are confused which one is which. As far as I recall, this is native from Vista / Longhorn onwards, you can probably get it in XP by copying it from another machine. Also, the new /MT switch for Robocopy which allows you to do multithreaded copying. | ||||
|
feedback
|
|
Start typing a command that is in your history, then hit F8 to complete the command from your history. Repeatedly hitting F8 cycles through matching elements of your history. eg if you've run the following commands:
If you enter "di" then hit F8 it will complete firstly with:
press F8 again to see:
Great for those long compilation command-lines. | ||||
|
feedback
|
