38

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?

19 Answers19

45

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.

Daniel H
  • 1,696
33

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.

Gareth
  • 19,080
Gnoupi
  • 8,188
27

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.

Ray
  • 722
21

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:”
harrymc
  • 498,455
15

Pressing F7 will list the last executed commands.

cd \ to get back to the c: directory.

Hugh Allen
  • 10,120
8

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

Gareth
  • 19,080
7

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

And more can be found via google.

harrymc
  • 498,455
7

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.

JYelton
  • 3,277
4

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.

4

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

Gareth
  • 19,080
OscarRyz
  • 4,141
2

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!

Phoshi
  • 23,483
1

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.

drby
  • 365
1

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.

Yuval
  • 2,302
1

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 :)

salmonmoose
  • 1,701
1

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.

1

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! :)

1
  • 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.

stone
  • 1,197
0

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.

John Weldon
  • 1,709
0

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

Gareth
  • 19,080
Vinayak
  • 611