Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to learn to use the command prompt better on Windows to have more control over what I do and just for the learning experience. The main annoyance I have right now is all of the typing. If I want to perform an operation on a file with a large path I'm sitting there typing it out for a minute at least, and if I make a mistake I have to press the up arrow key and scroll through the entire thing and find what I did wrong. Is there any tools to make this easier?

share|improve this question
    
I would love the Windows command prompt to have the "-o vi" option that bash does. It makes things very fast ( when you know a bit of vi of course ) – OscarRyz Sep 8 '09 at 2:09
2  
Tab completion! Any decent terminal will have it (and if it doesn't I'd question the capability of the terminal you're sitting at). – new123456 May 4 '11 at 12:25
    
Especially if you're learning, learn PowerShell. For old farts, learning a new trick can be difficult. But for beginners, it is good to get this advice early so as to direct your learning energies along the best path from the very start. – music2myear Jun 14 '11 at 14:56

19 Answers 19

up vote 33 down vote accepted

If you intend to use the command prompt only under Windows, you could use Windows PowerShell, as it is easier to use than the initial command prompt, and copies some behavior from the *nix-like terminals. (It provides also a lot more functionalities, but at first, at least to me, it's an "easier command shell").

picture of powershell

Edit: Changed picture for a more "friendly" one.

share|improve this answer
    
by the looks of wikipedia the picture looks a bit harder than what im using right now. I am still sort of struggling to learn windows let alone one of these *nix terminals but i will check it out thanks. – Adam Sep 1 '09 at 5:10
3  
Yes, in this case maybe it's not really adapted. To me, as I knew *nix terminals before, this powershell helped me, as it also provides a lot of aliases(shortcuts) for usual *nix commands. Typically, "ls" works like "dir". In general, it's also more consistent for the "tab completion", in my opinion, compared to the original shell, which makes it easier to navigate. – Gnoupi Sep 1 '09 at 5:19
1  
PowerShell really is the way to go. As a long time user of cmd.exe I can tell you that it's really limited. Once you want to do anything clever, you'll end up needing VBScript or something similar, so you'll have to learn that. Each command has its own syntax and they're rarely similar so you have to learn each one and can't guess easily. PowerShell is much more powerful and much more consistent so you can apply what you've learnt from one command to another. – serialhobbyist Sep 1 '09 at 13:19
    
Plus some of the PoSh commands have aliases which are the same as the cmd commands to make transition easier. E.g. dir works (aliased to Get-ChildItem). But in PowerShell you can also dir the registry and other things. – serialhobbyist Sep 1 '09 at 13:20
1  
Also, PowerShell has MUCH better (IMO) help text. Anyone ever tell you to read the cmdpages? – Hello71 Jul 5 '10 at 1:18

You can use the Tab key to auto-complete file names. Although keep in mind you must first type enough of the file name to uniquely identify it or else you will have to shuffle through incorrect matches. For example, you have a folder with these files and it is your current directory that you're sitting in with cmd:

.
..
Su.exe
Sup.txt
SuperUser.COM

if you wanted to auto-complete SuperUser.COM, you would have to type supe then press Tab, since none of the other files start with those 4 characters. Note that if you had typed su and then pressed Tab, you could press Tab twice more to reach SuperUser.COM or you could type ShiftTab to go backwards through the list and get there.

Another trick is if you have the file in an explorer window, you can drag it into the cmd window and it will type the name out for you.

share|improve this answer
2  
This works great thank you, but when i am tabbing through files sometimes i pass over mine, is there a way to go backwards? – Adam Sep 1 '09 at 5:11
14  
Yep, shift-tab :) – John T Sep 1 '09 at 5:12
2  
Bonus fact: shift + <any key that cycles through tabs/windows> is always equivalent to reverse e.g. alt-tab -> alt-shift-tab. – glenneroo Jan 20 '11 at 6:39
    
+1 for the long path trick! – tuananh Jan 31 '13 at 1:51

Here are some more tips and tricks in using the command prompt including:

"...drag n' drop files or folders from an explorer window into a command prompt; this inserts the quoted path as if you had manually pasted it..."

This is yet another way to reduce the amount of typing involved in long file paths.

share|improve this answer
3  
Now THAT's useful. I didn't know that one at all. – EvilChookie Sep 1 '09 at 7:35
1  
Already had that in my original answer :P – John T Sep 5 '09 at 5:40
    
This doesn't work in Windows Vista or Server 2008, but works again in Windows 7 and Windows Server 2008 R2. See superuser.com/questions/27347/what-is-conhost-exe/28897#28897 for a few details. – Reuben Sep 7 '09 at 18:06
    
The other advice there is very good as well – Casebash Sep 7 '10 at 5:49

Here’s the complete list of function key actions :

F1 retypes the previous command one character at a time
F2 brings up a dialog and asks “Enter the char to copy up to:”
F3 retypes the last command in full
F4 brings up a dialog and asks “Enter char to delete up to:”
F5 as for F3
F6 Print EOF character (Ctrl+Z)
F7 brings up a dialog of all the recent command history
F8 brings up each of the most recent commands, one at a time
F9 brings up a dialog and asks “Enter command number:”
share|improve this answer
1  
Has any one got F4 to work? The dialog appears but doesn't delete. – Charles Beattie Feb 4 '11 at 10:46

Pressing F7 will list the last executed commands.

cd \ to get back to the c: directory.

share|improve this answer
2  
Hmm, didn't know that. – Gnoupi Sep 1 '09 at 5:38
    
COOL! (that's all I have to say but a reply has to be 15 chars long...) – Traveling Tech Guy Sep 1 '09 at 12:40
    
I use the command prompt all of the time and I didnt know that F7 one - very handy! – Justin Oct 5 '09 at 11:01

Often you can reduce your typing by being in the correct directory. You can open a command shell in the directory you see in an Explorer window by adding cmd.exe in the folder type associations.

(Tools - Folder Options - File Types - Folder - Advanced - New - cmd)

Then, when you select cmd by right-clicking on that folder the command window that opens will have as its current directory that of the folder you clicked on.

alt text

share|improve this answer
1  
for XP users, MS Power Toys for XP will provide this for you as well: microsoft.com/windowsxp/Downloads/powertoys/Xppowertoys.mspx – akf Sep 5 '09 at 11:53
    
I knew there were various widgets that did this for you, but I always like a self-config that'll replace a widget. Thanks for this info. – music2myear Jun 14 '11 at 14:58

If Windows PowerShell is too overwhelming, there are also some cmd replacement shells:

And more can be found via google.

share|improve this answer
    
+1 for cygwin: using that toolset means the tricks you learn are portable to Linux installs and to a certain extent other OSs (BSD, MacOS, ...) where the same or similar tools and bash-a-like shells are present. Though if powershell is overwhelming, cygwin is likely to be too. – David Spillett Sep 1 '09 at 10:32
    
+1 for Console, which isn't a replacement shell, but a better terminal for existing shells. – wfaulk Oct 2 '09 at 21:23
    
+1 for Cygwin, but the emulator is awful. Would suggest Terminator + Cygwin, in that case. – jamesh Nov 18 '09 at 19:50
    
I'm a huge fan of TCC (have been since it was 4DOS, back around 1989); I much prefer it to PowerShell. And now that TCC/LE is freeware, I can send .BTM scripts complete with a TCC installation :-) Note that PowerCMD and Console are not replacement command processors, but replacement terminals. Personally, I use Console with multiple tabs, each containing a TCC (or Cmd, or Cygwin) session. – billdehaan Apr 8 '10 at 13:56
    
andlinux.org andLinux is much more user friendly than Cygwin. – user31752 Aug 16 '10 at 3:45

Something I use constantly while using command prompt is the up arrow (and down arrow) to scroll through recently used commands. Especially when I've entered a long command and only wish to edit some part of it without retyping it.

A short example, if you:

c:\>ping 192.168.1.1

And then want to ping another similar address, you can simply press the up arrow. The command appears on the prompt with the cursor at the end. This makes it easy to backspace once and change the address to 192.168.1.2 or something similar.

share|improve this answer

I suggest that you use the command prompt.

I know, it seems facetious, but this is serious---if not instantly helpful---advice. There is a lot to know, and to absorb it deeply, you have to use it over and over again.

share|improve this answer
9  
Yes, he wants to, but he would like to know what he can do with it, I think. Because "bruteforcing" the available commands might take some time. – Gnoupi Sep 1 '09 at 11:26
    
I learned the command prompt by writing an ambitious system deployment batch script. I tried to incorporate every feature I could think of that would benefit the desired task just kept asking questions in forums and of others I knew until it worked. 1500 lines and a lot of good experience that I still use. – music2myear Jun 14 '11 at 15:03
    
@music2myear you're 28, old enough. Where have you been that you didn't learn DOS in its day? – barlop Jun 16 '11 at 0:42
    
My dad bought our first computer when I was 10. DOS 4, I guess it was, and Win 3.1. I was only interested in painting apps and what games it could play. It wasn't until 98 that I got my own computer to study engineering. And it wasn't until that system started to have problems and I had to fix it myself that I really got into technology and computers. It was in 2003 that I got a job doing IT support and built the batch script I mentioned earlier. I was just a late starter by geek standards. – music2myear Jun 16 '11 at 16:09

Enable quick edit mode to:

  • Copy text by: select text + ENTER
  • Paste code by pressing right click.

enter image description here

I also change the Font and the layout to something more pleasant than the default bit map.

enter image description here

Finally add more rows and columns the the editing window, and more rows to the buffer.

enter image description here

Screenshots are in spanish, but they are exactly in the same place in english

share|improve this answer
1  
Changing the width of the console window is one of the first things I do on a new computer. – Justin Oct 5 '09 at 11:05
    
+1 Default height is just as useless. – glenneroo Jan 20 '11 at 6:36

Definitely grab a copy of Cygwin, and add its \bin folder to your PATH variable. It's like a usable command prompt!

But really, the only way to get used to it is to get used to it, so use it!

share|improve this answer
    
I have a hard time living with windows without my bash prompt – jweede Apr 8 '10 at 13:45

If you're using XP (don't know about Vista) you can download a powertoy that adds an "Open command window here" menu entry to your explorer folder context menu.

Something else that I've found useful is to stop using the windows default paths for everything. They are just too hard to remember and the spaces can become a problem. Using something more like linux' directory structure can be a real time saver. My directories look something like this (by way of examples):

 - C:\usr\bin\firefox 
 - C:\usr\bin\7zip
 - C:\usr\bin\dropbox

 - C:\usr\lang\cpp\gcc
 - C:\usr\lang\cpp\lib\qt_4_5_0
 - C:\usr\lang\python\py25

 - C:\usr\home\wrksp\cpp
 - C:\usr\home\doc
 - C:\usr\home\wrksp\svn

Way easier to remember.

share|improve this answer
5  
Vista (Ultimate Edition at least) has this by default, but hidden from the average user. Just hold down shift and then right-click a folder in the right-hand Explorer pane, and you should see "Open Command Window Here". – GAThrawn Sep 1 '09 at 9:06
    
@GAThrawn, I have Vista Home Premium and I confirm that I have seen this feature there too. – Shivasubramanian A Sep 3 '09 at 5:49
    
Is "C:\usr\bin\7zip" that much quicker to get to than "c:\Program Files\7zip"? In terms of keystrokes.. c:\prog<tab>\7zip vs c:\usr\bin\7zip maybe program files is quicker to get to? – barlop Jun 16 '11 at 0:40

Personally I think that if you want to learn to use the Command Prompt and are not finding it joyful, you probably don't need to use the Command Prompt.

As soon as you need to hit a CLI, you will find it useful, and even pleasant. If you're trying to do your day-to-day tasks with it, then you're bashing your head against a wall.

Once you are familiar with the command prompt, you may migrate your day to day tasks there just because it's easier than always reaching for the mouse :)

share|improve this answer
    
So true. Necessity breeds familiarity. – J. Polfer Sep 1 '09 at 15:16

Make use of environment variables.

For example, instead of typing c:\documents and settings\username you can simply use %userprofile%. For a list of standard environment variables, type SET and press enter on a command prompt.

In addition, get familiar with commands that are available to you - I like two sites for them: www.ss64.com and www.robvanderwoude.com

You can also learn batch scripting - using that, you can automate frequently used tasks.

share|improve this answer
  • To paste into a command window using the keyboard, press alt-space, e, p.
  • To repeat the last command that started with the letter "d" (for example; it could be any character) press d and then F8.

The latter tip may sound kind of obscure, but when you spend a lot of time in the console it can be much faster and easier than pressing the up arrow or F8 several times.

share|improve this answer

There are some great tips posted in this thread!

In my opinion posting CMD replacements is rather 'Off Topic'. But it seems to be OK here so I might add ColorConsole to the list.

The tabbed interface, Favorite Commands menu, Copy/Cut & Paste and indeed HTML export are very useful features that I don't want to miss anymore.

p.s.: try this in the "Must have Firefox addons" thread: Lads, get Opera, it's got the goodies aready built in! :)

share|improve this answer

You may find "Useful Command-line Commands on Windows" from Server Fault helpful. Actually, there are quite a few interesting command-line questions there, go have a look.

share|improve this answer

I agree with the suggestion to use powershell. In addition I find it incredibly useful to set up functions and aliases to reduce common tasks to fewer letters typed.

For example, to launch a http link I set this up in my powershell profile:

function browse-url { param($url="http://www.google.com/"); (new-object -com shell.application).ShellExecute($url); }
set-alias -name "browse" -value "browse-url"

and then I just type browse to open google, or browse http://.... to open a specific link

Another example for listing files or directories:

function lsa { param($path="."); Get-ChildItem -Force $path }
set-alias -name "la" -value "lsa"
set-alias -name "ll" -value "lsa"
function lsd { param($path="."); lsa $path | ? { $_.PSIsContainer } }
function lsf { param($path="."); lsa $path | ? { !$_.PSIsContainer } }
function lat { param($path="."); lsa $path | sort -property lastwritetime -descending }
function latr { param($path="."); lsa $path | sort -property lastwritetime }
function fi { param($pat,$root="."); gci -r $root | ? {$_.Name -match $pat} | % { $_.FullName } }

And then I use lsa to show all items in a directory, including hidden items. Use la or ll as even shorter aliases.

I use lsd to list only folders, lsf to list only files, lat to list ordered by last write time, and latr to list by time in the opposite direction.
fi was set up as a simple substitute for the unix find command, just recursively look for a file name.

share|improve this answer

Install the Windows Explorer replacement Xplorer2. It includes a command prompt tool that allows all functions of the command prompt ALONG WITH the Windows GUI like use of the mouse, right-click for copy-paste functions etc. Take a look the screenshot below.

Command Prompt Screenshot

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.