Monday, September 20, 2010

DOS commands on Windows XP

Windows 3.1,95,98 and me are all DOS based, so it was appropriate to use the term  "DOS commands". However,Windows NT, 2000, XP, 2003 and Vista are all NT based, so the term "DOS commands" in this case is a misnomer.It is more appropriate to use the term "command line interface" and "command line commands" instead of  DOS commands. Anyway, this section discusses the use of DOS commands in the context of  Windows XP.

Getting Started
To start using command line commands, you need to start a command line interface (CLI). In Windows XP, this can be done as follows:

  • ˆ Click “Start”
  • ˆ Select “Run...”
  • ˆ ‘type ‘cmd”
  • ˆ click OK

A “DOS box” should open. Again, calling this window a “DOS box” is also incorrect. The correct term is CLI.

Basic Commands

This section discusses the basic commands. You can look up the complete help text by typing help command in a CLI(and substitute command with the actual command that you want to look up).


  • ˆ copy: for copying files
  • ˆ xcopy: for copying folders
  • ˆ del: for deleting files
  • ˆ rmdir: for deleting folders
  • ˆ dir: for listing files in a directory (folder)
  • ˆ cd: for changing to another directory
  • ˆ edit: this is a text-mode editor for editing text files
  • ˆ ren: for renaming files
  • ˆ chkdsk: for checking the integrity of a partition
  • ˆ defrag: for defragmenting a partition
  • ˆ ipconfig: for setting and viewing networking configuration
  • ˆ ping: for checking connectivity to another computer


Use the command help to find out more about each of these commands. Note that the GUI of Windows XP also contains help for command line commands.

Shortcut Keys
In the CLI, you can use shortcut keys to make editing commands a little easier:

  • ˆ backspace, del, left/right arrow keys: they allow you to edit a command line.
  • ˆ up/down arrow keys: they select a command from a history of commands that you have used recently. The up-arrow key goes up in history (more ancient), and the down-arrow key goes down in history (more recent).
  • ˆ tab: you can use the tab key to perform “file name completion”. This means if you have a file called abcdefgh.txt in the current directory, you can type abc, then use the tab key so the CLI completes the entire filename for you. If there are multiple files starting with abc, you can press tab one more time to list all such files.

Some more about the CLI
Basic Command Format


Most CLI commands are issue using the following format:

  • ˆ The first item on the left hand side is the command. The command lets Windows know what you want to do. Most commands have names that are less than or equal to 8 characters.
  • ˆ The command can be followed by a number of options. options are optional. They specify certain options for a command. Most options in Windows begin with a slash symbol (/).
  • ˆ Options can be followed by parameters. A parameter is a piece of information that a command needs. In most cases, a parameter is either the specification of a file, a folder, files, folders, or a drive letter.

For example, you can use the following command to list all the files starting with a name of xyz:


dir /w xyz*.*

In this case, dir is the name of the command, /w is an option to specify wide format, and xyz*.* specifies all files with names starting with xyz.

Full File and Folder Names

Each file and folder in a system has a full name. It begins with a drive letter. A drive letter is an alphabet letter (’a’ to ’z’) followed by a colon (:). By convention, a: usually refers to the floppy disk drive. b: is not used on most modern computers (it refers to the second floppy disk drive on very old computers). c: usually refers to the hard disk in a system. Most systems only have one hard disk, which makes d: refer to the CD/DVD drive.

After the drive letter is a backslash symbol (\). This first backslash symbol has a special name. It is called the root directory of a drive.
Following the root directory is potentially a series of subfolders, separated by backslash symbols. Note that if a file is in the root directory, there is no subfolder in its full path name. As an example, C:\WINDOWS\SYSTEM32 specifies SYSTEM32 is a subfolder in WINDOWS, and WINDOWS is a subfolder of the root directory of the C: drive.

The second last component of a full path name is the name of a file. In old systems, this portion can only have
up to 8 characters. However, in later versions of Windows, this portion can have as many as 254 characters. The last component of a full path name is the extension of a file. The extension of a file is conventionally up to three characters. However, extensions of more than three characters are also permitted. An extension lets the system know what kind of a file.

The file name and file extension are separated by a single period (.).
Note that you can have multiple files with the same name but different extensions coexisting in a folder. In other words, readme.txt, readme.html and readme.doc can all coexist in a folder.
Although unconventional for Windows and DOS, folder names can also contain extensions.
An example of a full path name is as follows:

C:\Program Files\TakWare\bin\virusx.exe

In this example, the file has a name virusx and an extension of exe. Any file with an extension of exe, bat or
com can be executed. This file is located in a folder bin. bin is a subfolder of TakWare. TakWare is a subfolder of Program Files. And, Program Files is a subfolder of the root directory of the C: drive.

Current Directory

For convenience, there are many ways to specify files and folders in a CLI. This is a flexibility that is not available in the GUI. Each CLI (DOS box) has a context. Part of this context is known as the “current directory”. This context makes it possible to simplify commands. Without a “current directory”, a file always needs to be specified by its full name.
However, with a "current directory", a file can be referred to using a convention that is relative to the current directory. When you start a CLI, the current directory is usually C:\WINDOWS. You can change the current directory using the cd (abbreviation of Change Directory) command.
The current directory is a part of the CLI command prompt. It appears on each command line on the left hand side.

Examples of Basic Commands
This section provides some examples of the basic commands.

cd \Program Files\QuickTime

This command changes the currnet directory to \Program Files\QuickTime of the same drive letter of the previous
current directory (usually C:). Note that the command prompt should be changed to C:\Program Files\QuickTime accordingly.

dir

This command lists the content of the current directory in the "long format". The long format displays the last modified-time, size, name and extension of a file. In addition, the long format also shows the number of file and folders listed.

dir /w

This command lists the content of the current directory in the "short format". The short format only displays the name and extension of each file. But it also summarizes the number of files and directories listed.

dir /w ..

This command lists the content of the parent directory in the short format. In our example, it displays the files and folders in C:\Program Files because it is the parent of the current directory, C:\Program Files\QuickTime.

chkdsk /f c:

This command requests the operating system check the integrity of the C: drive, and fix any detected problem
automatically. The option /f specifies "to fix any detected problem". Note that this command usually ends up with a question asking whether you want to complete the operation when the system reboots.

defrag -f m:

This command requests that the operating system defragment the M: drive. The option -f tells the operating system to defragment even if defragmentation is not recommended. Note that this is one of the very few cases where an option begins with a minus symbol (-) instead of a slash symbol (/).

ipconfig

Without any parameters, ipconfig displays a summary of all the network interfaces of the system.

cd ..

This command changes the current directory to the parent directory. In our example, because we were in C:
\Program Files\QuickTime,this command changes the current directory to C:\Program Files.


dir /w *.exe

This command lists all the files in the current directory that ends with .exe as an extension. The listing is in “short format”, as specified by the /w option.

del *.*

This command is extremely dangerous, do not execute it unless you know what you are doing! This command erases all the files matching any name and any extension. Effectively, it deletes every files in the current directory. This command does not, however, delete subdirectories. Nonetheless, you risk losing lots of files and data.

No comments:

Post a Comment