Use WinXP Command Prompt
Non-Geeks are naturally a bit inhibited from going anywhere near command prompts and of using text as their input to run programs or navigate around their computers. We hope that this article helps to overcome such inhibitions since the command prompt is still a very, very useful tool on occasions.
The following tips work from a Windows XP cmd prompt and it is probably the same or similar under the other NT OSes. Note that CMD and COMMAND are two different utilities even though the resulting consoles may look the same. The NT-based Command Prompt is technically not, as some call it, a DOS Prompt, since the NT-based OSes don't use DOS. There is some overlap between usage but they are completely different applications. For a list of actual DOS commands you could do worse than look at MS-DOS 6.22 and Up but remember that they are DOS commands and not designed to run under NT-based operating systems.
You can open a console by entering CMD into the run box or by using the Command Prompt icon in the Acessories section of the Start menu. The default prompt should open at your own or current "UserProfile" typically at:-
C:\Documents and Settings\Current User Name>
Navigating straight to a particular folder from the Desktop or from My Computer
- If you want to open the console right at the C:\> prompt itself you can issue a more elaborate line (CMD /k C: && CD.. && CD..) into the run box. The drive immediately after the /k switch is the drive which the command prompt should open. It will open at the default folder in that drive as accessed within any Command Prompt session. The && blocks separate commands that you would issue yourself at the resultant prompt. Enter cmd /? into the run box to see all the various options that can issue with the cmd application.
- If you regularly want to go straight to certain folders at a
Command Prompt
then install the WinXP PowerToy Open
Command Window Here. This allows you to first navigate to the
location in My Computer and to then Right Click on the relevant folder
and
choose "Open Command Window Here" from the shortcut menu list. This
utility is equivalent to "Drop to DOS" under earlier versions of
Windows.
Changing Directories and Drives
- The common way to move back through parent directories is to use CD.. Entering this twice in succession at your "UserProfile" prompt should get you back to the C:\> prompt but you can also use CD C:\ (note the trailing back-slash) to get the same effect.
-
C:\Documents and Settings\Current User Name> CD C:\
C:\>
- Use cd to change directories within a partition but simply enter another drive letter and a colon to change drives. The console remembers (for the duration of the current command window session) where you were when you were last in a particular partition and it should take you back to the original full path if you return to that partition: viz:-
-
C:\> CD folder1
C:\folder1> CD folder2
C:\folder1\folder2> D:
D:\> C:
C:\folder1\folder2>
-
C:\Documents and Settings\Current User Name> D: D:\> C: C:\Documents and Settings\Current User Name>
- The System Variable %UserProfile% can be used to go straight to that folder in both Windows Explorer (My Computer) and Internet Explorer and also (when within the approriate drive letter) to go straight to that folder at the Command Prompt. (Equivalent results should pertain to other variables such as %WinDir% and %ProgramFiles% ).
C:\> CD %UserProfile% C:\Documents and Settings\Current User Name>
-
The suffix /? can be
used with most commands to see the various options/switches available. So if you want to list the options
for cd (change directory) then (equivalent
results should pertain to dir,
xcopy, etc, etc) issue the following command.
-
C:\> CD /?
Copying and Pasting
-
You may be surprised if you attempt to paste with the usual
CTRL+V keyboard shortcut inside a console window. All this will do is
enter
^V. In order to paste from the clipboard you should either RightClick
on the Window and choose Paste or choose Edit after Right-Clicking on
the Title Bar.
- In order to copy from the console itself you should RightClick, as above, but choose Mark. Then highlight the area to copy and press Enter to place a copy of the highlighted area onto the Clipboard.
- If you want to simply get a particular path onto the clipboard you could install Camtech's CopyThisPath, which lets you copy the path from any chosen folder in My Computer after RightClicking on the Folder or File. (The same link has a number of other very useful little utilities).
Unhiding
- Files and folders with attributes which inhibit their use or accessibility can be quite easily visualised within Windows by adjusting the Folder Options from the My Computer's "Tools" menu. When wanting to see hidden items from a command prompt the files must actually have such hidden attributes changed to allow then to be seen at all. You can specify specific files or, as in the following example, all the files in a folder. First navigate so that the cursor is in the relevant parent folder and then issue ATTRIB -h -s -r *.* followed by DIR /p: (the /p switch prevents the results scrolling all the way through a long list).
-
C:\>CD FolderWithHiddenStuff
C:\FolderWithHiddenStuff>DIR /p
Volume in drive C is SYSTEMX
Volume Serial Number is 4295-9561
Directory of C:\FolderWithHiddenStuff
15/03/2007 17:18 <DIR> .
15/03/2007 17:18 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 1,451,515,904 bytes free
C:\FolderWithHiddenStuff>ATTRIB -h -s -r *.*
C:\FolderWithHiddenStuff>DIR /p
Volume in drive C is SYSTEMX
Volume Serial Number is 4295-9561
Directory of C:\FolderWithHiddenStuff
15/03/2007 17:18 <DIR> .
15/03/2007 17:18 <DIR> ..
1 File(s) 13 bytes
2 Dir(s) 1,451,515,904 bytes free
15/05/2007 11:44 13 hiddenfile.txt
Command Switches
- Switches are suffix entries that follow any command. As mentioned
earlier using the switch /?
will list all the various options. Here is an example using the COPY command.
-
C:\>COPY /?
Copies one or more files to another location.
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.
To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format)
- The values inside square brackets [ ] are optional.
- The values separated by a pipe | are choices.
- The ellipsis . . . means and so on.
- The source and destination can both given by an absolute path but if no path is specified the current folder will be used as the standard input or output. The following should, for example, copy all (visible) files from a D:\Documents folder to a C:\Bob\TextFiles folder (whose path is the standard input since that is where the cursor was placed). The files would be listed and enumerated as the copying proceeds. Only files and not folders are copied. To copy both files and folders the XCOPY command is needed.
-
C:\Bob\TextFiles>COPY D:\Documents\*.*
Standard Input/Output
- In the absence of a specifed path, the system defaults to the current folder indicated by the cursor. This is the Standard Input and Output location depending on whether the file i/o is in or out. The output display that would have been shown in the Command Prompt Window can, for example, be directed instead to a text file.
-
C:\Bob\TextFiles> COPY D:\Documents\*.* > list.txt C:\Bob\TextFiles>
- The command above thus outputs the lines of text into the file C:\Bob\TextFiles\list.txt rather than simply display them in the Command Prompt console.
Console can Remember Things
- After opening a Command Prompt Window or Console the application will remember various things until the session is closed. Each drive letter will retain the last path used by that drive letter when returned to as already outlined above. Another very useful thing to know is that the up and down arrow keys ↑ and ↓ can be used to scroll through all previoulsy entered commands for the current session. This can make re-entering the same or similar text much simpler. The left and right arrows ← and → can move the cursor through the current line of text for editing.
- You can also change/customise the prompt itself with the PROMPT command. See PROMPT /? for details. This isn't generally all that useful; try the $T switch for a bit of fun:-
-
C:\>PROMPT $T
Files versus Folders
- Files and folders are generally treated quite differently at the
Command Prompt:-
Deletion: RD is used to Remove Directory but DEL is use to delete files.
Creation: MD is used to Make Directory and the is no file equivalent.
Copying: XCOPY is used for copying Folders and COPY is used for copying files (only visible files/folders are so treated unless there are special switches used.
Renaming: REN is however the same for both. - Remember you can use the /? switch to get further details about all of the above.
Mode Variations
- Depending on its current mode the Command Prompt may not like gaps/white-space inside paths. If it objects to such entries then enclose the whole path in quotes: e.g. "C:\Program Files\Fun And Games\Got Some Info Here.txt"
Related Links
- Microsoft Windows XP - Command-line reference A-Z
- Windows - Command Prompt Basics | Amset.info
- Windows XP/2000 Command Tools