TR Dojo: Five Windows command-prompt tips every IT pro should know
August 31, 2009, 11:49am PDT | Length: 00:07:18
Most Windows users may prefer the GUI, but IT pros recognize the power of the command-prompt. Bill Detwiler shows you five tricks for the IT ninja. Once you’ve watched this TR Dojo video, you can find a link to the original TechRepublic article and print the tip from our TR Dojo Blog.
Bill Detwiler: The Windows GUI may be easy for the average user to navigate, but power users and IT pros alike still recognize the usefulness of the command-prompt.
I'm Bill Detwiler, and during this TR Dojo, I'll show you four tricks that will help you become a command-prompt ninja.
Our first two tips come from Greg Shultz, one of TechRepublic's Windows bloggers. Greg points out that those who regularly work within the command-prompt probably know that you can cycle through a list of all the commands that you've entered within a particular session using the up and down arrows on your keyboard.
By default, this method will show you the last 50 commands that you've entered. If you'd like to go back a bit further or reduce the number of cached commands, Greg's first tip will let you do just that.
First, you'll need to access the command-prompt window's context menu. You can do this by right-clicking just about anywhere on the window's title bar or left-clicking the small command-prompt icon in the top, left corner. Now click Properties. On the Options tab, which is shown by default, locate the Command History section and then the Buffer Size setting. By changing this value you can increase or decrease the number of commands saved in the buffer.
Yet regardless of how you set this number, it can be frustrating, using only the arrow keys, to scroll through your previous commands. And that's where Greg's second tip helps.
Using the DOSKey command with the /history switch, you can see a full listing of all the commands stored in the buffer during the current session. This can be a much easier way to review previous commands without sorting through them one at a time.
When Greg first published his tips in the Windows blog, they proved pretty popular. But there are also plenty of Windows gurus in the TechRepublic community who were quick to offer their own command-prompt history tips.
Member mytmous (mighty mouse) posted that pressing F7 key opens a window showing the session's previously entered commands. With this window open, you can move through the commands using the arrow keys and hit ENTER to reuse any of them.
Member Kiwi.Dusty built upon mytmous' tip and posted a complete list of command-prompt function keys and their results. For example F3 retypes the last command, and F6 prints the end-of-file character, or Ctrl+Z. I'll post the entire list in the TR Dojo blog.
Members paul.harrison, greg.ross, and BrettK provided our fourth tip, which makes switching directories from the command prompt much easier. For example, if you don't want to type or can't remember a long folder name, you can use a wildcard or the tab key to speed things along. For example, entering:
Will open the C:\Documents and Settings directory.
Alternately, pressing the Tab key after typing cd will cycle through the current directory's sub-directories -- inserting them after the cd command but not switching to them. And, pressing Tab after entering cd and a character, or series of characters, will automatically insert the first directory (alphabetically) that begins with that character. For example, entering cd do and pressing tab automatically fills in the Documents and settings directory. Pressing Tab again, will cycle to the next sub-directory.
Our fifth and final tip came from another group of TR members. Davids, jnickell, and philrunninger teamed up to write a couple of batch files that let you log your command-line sessions and then query that log for specific information.
I'll post the code for these batch files in the TR Dojo blog. You can then use that code along with your favorite text editor to create the batch files. Once you've saved the files, I've named them q.bat and h.bat (but you can name them whatever you want), place them in a location that you can easily access from a command prompt, such and the root directory on your C: hard drive.
Now, after taking care of business at the command prompt, enter q (for quit) instead of entering the word exit to end your session and close the window. The command history for you session will now be stored in a text file.
If you want to search your command history for a specific command, you can use the second batch file, name h.bat. From the command prompt, just enter h followed by a search parameter. For example, entering the command:
shows you all the ping commands you issued.
Now, Greg's initial tips were pretty handy great by themselves, but it was TechRepublic members who really shined on this one. And I'm going to be sending each of the members featured in this TR Dojo video a TR coffee mug.
If you have any great command-line or Windows tips, share them with us in the TR Dojo blog.
For more teachings on your path to becoming an IT Ninja, visit trdojo.techrepublic.com. And please let us know if this tip was helpful.
You can also submit your favorite IT Ninja tips by e-mailing them to us at email@example.com. If we use them for an episode of TR Dojo, we'll send you a TechRepublic coffee mug.
I'm Bill Detwiler. Thanks for visiting the TR Dojo.