Chapter – 7
Necessary DOS Commands
Introduction
While we try to recover the data from the disk, it depends on the case of data loss that how much effort is required to recover the loss. In many cases it is possible that if we have the sufficient knowledge of some important DOS (Disk Operating System) commands, we may recover data with fewer efforts.
In some cases it may be possible that we can recover data without programming only by use of these commands with a tricky mind.
I assume that you do not know anything about DOS and its commands. In this chapter of DOS commands introduction we’ll learn only about those command which may help us for recovering our data. First of all we’ll give a glance to the evolution of MS – DOS.
Brief History
The MS – DOS operating system is based on the Intel 8086 family of microprocessor. MS – DOS has evolved from a simple program loader into a sophisticated, stable operating system for personal computers.
Microsoft Disk Operating System (MS-DOS) Version 1.0
IBM developed this computer in the early 1980s. Microsoft developed MS-DOS 1.0. Released in August 1981, it consisted of 4000 lines of assembly language source code and ran in 8 kilobytes of memory.
Shortly after that, in 1982, MS-DOS version 1.1 was released and worked with double sided 320kb floppy disks. Versions of DOS marketed by IBM are called IBM-DOS or PC-DOS.
MS-DOS Version 2.0
When IBM began development of a 10-megabyte hard disk, Microsoft began work on the development of version 2.0 of DOS, which would be designed to support the hard disk. Up to this point, DOS 1.0, in keeping with its heritage, had been designed for a floppy disk environment. One of the major limitations in DOS 1.0 is that its directory is limited to a maximum of 64 files.
MS-DOS version 2.0 was so designed to include a hierarchically designed file system. A hierarchical file system is significant in that any directory can contain both files and other subdirectories. Hierarchical file systems were already in use in the UNIX operating system, which was used as the development platform of the MS-DOS/IBM-DOS operating system. In effect some of the underlying concepts of MS-DOS are similar to their counterparts in UNIX.
MS-DOS Version 3.0 to 5.0
Version 3.0 was released in August of 1984 to support the IBM PC/AT. Version 3.1 was released in November 1984 and contained networking support. The January 1986 version 3.2 supported 3.5-inch disks. In 1987 IBM version 3.3 followed, with the principal purpose of supporting the IBM PS/2 line of computers.
The MS-DOS version 3.3 added many new features and commands. Compaq version 3.31 of DOS allowed for hard disk partitions larger than 32 megabytes.
MS-DOS version 4.01 also reads partitions greater then 32 megabytes. Originally issued as MS-DOS 4.0, some minor bugs resulted in upgraded version 4.01 being issued with various fixes. This version added full screens, a menu-driven interface called DOS SHELL, and extra support for Expanded Memory Specifications.
Version 5.0 was designed as a replacement for all preceding versions of DOS. With DOS 5.0 both IBM and Microsoft were selling the same DOS even the documentation was similar. Memory requirements were significantly reduced. Significant enhancements were made to the support for expanded and extended memory.
The DOS editor "EDIT" was included with this version of DOS. The DOS SHELL is completely new. QBASIC was introduced to replace BASICA and GWBASIC. This version offered a way to recover data that had been accidentally lost at least some of the time.
MS-DOS Version 6.0
Version 6.0 included many new programs to enhance the performance of DOS. They included:
- Microsoft Double Space, an integrated disk compression program that increased available disk space by compressing files
- Microsoft Mem Maker, a memory-optimization program that makes it easy to move device drivers and memory-resident programs from conventional memory into the upper memory area
- An enhanced EMM386.EXE device driver that provides access to more upper memory blocks
- Enhanced loadhigh and devicehigh commands that enable you to specify the memory region in which to load a program
- Microsoft Backup, a program that makes it easy to back up your data
- Microsoft Anti-Virus, a program that can identify and remove may different computer viruses
- Microsoft Undelete, an enhanced program that enables you to choose one or three levels of protection in case you accidentally delete a file,
- The ability to include more than one configuration in the CONFIG.SYS file. The ability to bypass startup commands when you turn on your computer
- MS-DOS Help, a complete online reference to MS-DOS commands
MS-DOS Version 7.0 (Windows 95)
DOS is provided with Windows 95 for backward compatibility with DOS and Windows 3.x applications. Let us see the evolution of MS – DOS to Windows in the following table:
MS – DOS Version |
Notes and Comments |
MS- DOS 1.0 |
First operating system on IBM PC in 1981 |
MS- DOS 1.25 |
Double sided disk support and bug fixes added |
MS- DOS 2.0
|
Introduced with IBM PC/XT in 1983 and having the support of hierarchical file structure and hard disks added. |
MS- DOS 2.01 |
2.0 with international support |
MS- DOS 2.11 |
2.01 with bug fixes |
MS- DOS 2.25 |
Support for Extended Character sets |
MS- DOS 3.0 |
Support for 1.2MB floppy disks and larger hard disks added |
MS- DOS 3.1 |
Support for Microsoft networks added |
MS- DOS 3.2 |
Support for 3.5 inches disks added |
MS- DOS 3.3 |
Generalized code page (font) support |
MS- DOS 4.0 |
Support for logical volumes larger then 32 MB and Visual shell |
Windows 1.0 |
Graphical user interface for MS – DOS |
Windows 2.0 |
Compatibility with OS/2, Presentation Manager |
Windows 95 |
Used Version 4.00.950 |
Windows 95 Se |
Used Version 4.00.1111 |
Windows 98 |
Used Version 4.10.1998 |
Windows 98 Second Edition |
Used Version 4.10.2222 |
Windows Millennium |
Used Version 4.90.3000 |
Windows NT |
Used Version 4.0 |
Windows 2000 |
Used Version 5.00.2195 |
Windows XP |
Used Version 5.1.2600 |
Necessary Commands
Let us learn some important commands that may be useful while we are trying to recover data by programming and non programming techniques:
ATTRIB
The ATTRIB command is used to display, set, or remove one or more of the four attributes, read-only, archive, system, and hidden that can be assigned to files and directories. It is typically used to remove read-only, hidden, and system attributes so a file can be moved or deleted or also to set them so that it can not be.
Syntax:
To display the attribute settings of all files in the current directory:
ATTRIB
To display the attributes of a directory:
ATTRIB directoryname
To display the attributes of a file:
ATTRIB filename
To set or remove attributes of a file or directory:
ATTRIB [ + | - R] [ + | - A] [ + | - S] [ + | - H] [directory|filename] [/S]
+ Sets an attribute, - Clears an attribute.
R |
Read-only file attribute. |
A |
Archive file attribute. |
S |
System file attribute |
H |
Hidden file attribute. |
/S |
Processes files in all directories in the specified path. |
The Read-Only attribute allows a file to be accessed but not modified. The System attribute is normally reserved for files that are necessary for DOS or Windows to load properly. Files and directories with the Hidden attribute set are not normally displayed in directory listings or Open Files dialogue boxes.
The usual reason for hiding folders is because they are important to system or program operation and should not be deleted or moved in casual tidy-up operations. Hidden and System folders will often also have the Read-Only attribute set.
Multiple attributes can be set or cleared by combining switches, separated by spaces. Although both files and directories can have attributes assigned and cleared using ATTRIB, there are differences in the way they behave - the most obvious of which is that wildcards (? and *) can be used to display or change the attributes for a group of files whereas directories must be named in full. We are going to know in details about wildcards and shortcuts later in this chapter.
Setting a file attribute to System, Hidden, or Read-Only, will prevent the file from being deleted or moved using DEL, ERASE, or MOVE commands but will not protect the files from DELTREE or FORMAT. Although a directory's Read-Only attribute can be set, this seems to serve little purpose.
Firstly, the attribute only applies to the directory and not the files within it. Also setting a folder to read-only does not prevent it being deleted however in Windows explorer it will cause a warning notice to be displayed before the folder is deleted or moved.
To display the attributes of a file named "readme":
ATTRIB readme
To assign the Read-Only attribute to the file "readus.txt", use:
ATTRIB readus.txt +R
To remove the System and Hidden attributes from "data19.txt":
ATTRIB -S -H data19.txt
To hide the directory "c:\mynotes"
ATTRIB +H c:\mynotes
To hide the files, but not the directories in the C:
ATTRIB +H c:*.*
CD (or CHDIR)
Changes (or displays) the current directory on the specified drive.
Syntax:
To display the current directory:
CD [drive:]
To change the current directory:
CD path
Path Changes the current directory to path. Each drive has its own "current directory" which remains "current" until it is changed thus changing the current directory of drive c: will not affect the current directory status of any other drive. To change to the current directory on a different drive, just enter the drive letter and colon.
If the current drive is c:, to enter the directory "
c:\windows\java"
CD \windows\java
If the current directory is already "c:\windows", all that is necessary is:
CD java
To change the current directory "c:\windows\java" to the parent directory "c:\windows":
CD..
Suppose you are currently in director “c:\windows\java\notes\klip\”, now if you directly want to jump to the windows directory, just increase the two more dots (..) you we did in the previous case, like this
CD….
If the current directory on the c: drive is "c:\windows\notes" and the current directory on the e: drive is "e:\movie", then to copy all files from "e:\movie" to "c\windows\notes":
COPY e:*.* c:
To copy all files from "e:\downloads" to the root directory of c:
COPY e:*.* c:\
CHKDSK
CHKDSK is used to check the status of a disk, fix some disk errors, and display a status report showing any errors found in the file allocation table (FAT) and directory structure. CHKDSK also displays a summary of disk usage. If errors are found on the disk, CHKDSK displays a warning message.
Syntax:
CHKDSK [path] [/F] [/V]
Path Specifies the drive and directory to check.
/F Fixes errors on the disk.
/V Displays the full path and name of every file on the disk
SCANDISK can reliably detect and fix a much wider range of disk problems and is generally preferred to the somewhat dated CHKDSK. The /F switch (for fixing any errors found) should not be used while any program is running other than DOS and CHKDSK itself.
CHKDSK cannot be used on drives created using SUBST, nor can it be used on network drives. In win98, CHKDSK does not check the disk, though still provides some basic data
You should not scan the disk with CHKDSK or SCANDISK or any other disk scanning program if your disk is crashed or there is any logical error in your boot sectors like MBR, DBR, FAT or root directories are corrupted. It may make you data information distorted and can make it difficult to recover. Not only this you may not recover data completely. |
CLS
Clears the screen leaving only the command prompt and cursor.
Syntax:
CLS
COMMAND
Starts a new copy of the Command Interpreter.
Syntax:
COMMAND [path] [device] [/Switches]
Path Drive and directory containing command.com. This must be specified unless command.com is in the root directory.
Device Device to use for command input and output. By default this is the keyboard and monitor
/P Makes the new Command Interpreter permanent.
/E:x Sets the initial environment size [bytes]. x should be set between 256 and 32,768 bytes. The default is: 256 bytes.
/L:y Internal buffers length [bytes]. y should be set between 128 and 1,024 bytes. This switch is only accepted if the Command Interpreter is permanent. The /P switch must also be set.
/U:z Input buffer length [bytes]. z should be set between 128 and 255 bytes. The default is: ? This switch is only accepted if the Command Interpreter is permanent. the /P switch must also be set.
/MSG Stores all error messages in memory. This switch is only accepted if the Command Interpreter is permanent. The /P switch must also be set.
/LOW Forces COMMAND to keep in low memory
/Y Steps through the batch program specified by /C or /K
/C command Executes command and exits. This must be the last switch on the command line.
/K command Executes command and continues running. This must be the last switch on the command line.
COPY
The prime use of COPY is to copy one or more files to another location but it can also be used to combine (append and concatenate) files and to type directly to a file, printer, or other device.
Syntax:
COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]]
[destination [/A | /B]] [/V] [/Y | /-Y]
source The file(s) to be copied. Although this must be a single parameter, it may include multiple files specified using wildcards (* or ?). It may also be a valid device (e.g. CON)
like COPY CON NOTES.TXT
now write or copy the text and come out by entering the key Ctrl+Z.
destination The directory and/or filename for the new file(s). If destination is not specified source is copied to the current directory with the same name and creation date as the original. If source is in the current directory, an error message is displayed stating that the "file cannot be copied to itself”.
file /A Forces COPY to treat the file as an ASCII text file.
file /B Forces COPY to treat the file as a binary file.
/V Verifies that new files can be read.
/Y No warning prompt before overwriting a file.
/-Y Displays a warning and requires confirmation before
overwriting a file.
When used from the command line, if a file specified in destination already exists in the specified location, COPY will, by default, display a warning message and require confirmation before overwriting the old file. On the other hand, when COPY is used in a batch file, any existing files will be overwritten without warning.
This default behavior can be modified by presetting the /Y | /-Y switch in the COPYCMD environment variable and overruled by using the /Y | /-Y switch on the command line.
COPY does not copy files that are 0 bytes long; instead, it deletes such files. Use XCOPY to copy these files. Source and/or Destination may be an appropriate device (such as CON, COMx or LPTx where x is 1,2,3 exc.) rather than a file.
Depending on context, Copy treats files as binaries or ASCII text files. By default:
- When copying files from one location to another (ASCII or not), COPY assumes binary mode,
- When concatenating files, COPY assumes ASCII mode,
- When source or destination is a device (other than a disk), copy assumes ASCII mode.
When operating in binary mode, COPY determines the file's starting location from the File Allocation Table and copies the number of bytes allocated to that file from that point.
When in ASCII mode, data is copied until an End-Of-File (ASCII character no. 26; Ctrl-Z) character is reached. This character is NOT copied, but COPY adds an EOF character before closing the new file.
This convoluted procedure enables COPY to concatenate files and to work with non-file input (like keyboard). On the few occasions that the default mode is inappropriate, it may be over-ridden by adding the /A or /B switch to source and/or destination files as required.
To copy "note.txt" in the current drive and directory to the directory "mynotes":
COPY note.txt c:\mynotes
or
COPY note.txt c:\mynotes\
In the first case, if the "mynotes" directory doesn't exist, "note.txt" is copied to a file named "mynotes" in the root directory of drive C. In the second case, an "Invalid Directory" error message will be displayed. To copy all the files in the "mynotes" directory to a directory named "mynotes backup" on drive D:
COPY c:\mynotes\*.* d:\mynotes backup\
To make a copy of "note.txt" in the current drive and directory and call it "program note.txt"
COPY note.txt "program note.txt"
DEBUG
DEBUG is a method of looking at portions of your computer and writing assembly code to perform certain tasks on your computer. MS-DOS 2.x - 4.x used DEBUG.COM and MS-DOS 5.x and beyond used DEBUG.EXE for this.
DEBUG.EXE is one of those little programs that, in the hands of a skilled user, is an amazingly powerful tool with which one can view and edit the contents of memory both short term(RAM) and long term (hard/floppy/tape media). One can also compile (and, up to a point, decompile) assembly language code.
DEBUG is a byte editor that enables files to be viewed and modified at the byte level. It is generally recommended as there is no "undo" command, so make a backup before playing with it. Be sure that you know what you are doing when using the DEBUG utility.
This is a powerful programmer’s tool that can be used to gain access to your computer at the hardware level. If you are not careful, you could cause such damage as erasing your hard disk or locking up your keyboard.
Syntax:
DEBUG [filename]
DEBUG [[drive:] [path] filename [testfile-parameters]]
[drive:][path]filename Specifies the file you want to test.
testfile-parameters Specifies command-line information required by the file you want to test.
How to start DEBUG
DEBUG can be started in one of two ways.
Method one:
At the DOS prompt you enter
DEBUG (return)
DEBUG will respond with the hyphen (-) prompt. When the prompt appears DEBUG is waiting for you to enter one of its many one letter commands. Starting DEBUG this way will allow you to work on the internal hardware of the computer and view the contents of all of the memory location in RAM. You can also load in as many as 128 sectors of a floppy or Hard disk and view, edit or move the contents to another location.
DEBUG sets up a work area in memory of 65,535 (decimal) one byte locations which is equal to FFFF bytes in Hex. The first 256 (decimal) or 100 Hex bytes of this area are set aside for what is called the Program Segment Prefix (PSP) of a program and must not be altered in any way. Whenever we load sectors or data in memory with DEBUG, it must be put at a location starting at offset 100.
An example of a debug command is shown on the following line.
DEBUG
L 0100 0 0 80 (return)
In this command, We are telling debug to load into memory starting at offset 100, 80 (Hex) sectors from the A drive starting with sector 0. 80 Hex sectors is equal to 128 decimal sectors, so if each sector on the disk, stores 512 bytes then the total number of bytes loaded into memory is (512 X 128) or 65,540 bytes (Maximum).
Method Two:
At the DOS prompt you enter
DEBUG \path\filename (return)
DEBUG will then load itself into memory along with the file that is specified in the path and filename field of the command line and put the first byte of the file at offset 100 of the work area.
By starting DEBUG this way, we are able to view, edit or move a COM program or an ASCII text file. This is a very convenient way to DEBUG or fix a COM program.
MS-DOS will allow only two types of programs to run under its control and they must end with the extensions of EXE or COM. The difference in these two program types is in the way DOS handles the maintenance portions of the program.
This maintenance area, often called the Program Segment Prefix (PSP), is a 256 byte block of memory that must be set aside by the program and is needed by DOS to return control back to the operating system when the program terminates.
Without going into a lot of details, we shall point out the major difference between these two types of programs.
COM Extension
COM programs are very small and compact programs that cannot be larger than 65K bytes in size. The PSP of a COM program is located in the first 100 Hex (256 Dec) locations of the program. The first instruction of the COM program must start at offset 100 in memory.
DOS creates the PSP for the COM program, which means we don't have to be concerned with this when we assemble a program. All the data, code, and the stack area are in the same segment of memory (1 segment is 64K).
EXE Extension
The EXE programs can be any size from 200 bytes to 640k bytes. The PSP must be setup by the programmer, when the program is assembled. The programmer determines where the first instruction is in the program. The EXE program uses separate segments for the data, code and stack area in memory.
From the comparison of EXE and COM file properties, you can see it is much more difficult to assemble an EXE program than it is a COM program. The debug utility program was designed to work only with a COM program by setting up the PSP area each time we enter debug.
Once in DEBUG, we can start assembly of a program at offset 100 and not be concerned with PSP or where the data, code, and stack is located. It is possible to look at an EXE program with DEBUG if we rename the program with a different extension before we load it into memory.
After DEBUG starts, type ? to display a list of debugging commands. To get out of DEBUG you need to "Q" and enter. To execute the DEBUG routine you need to do "G" and enter.
Let us see an example:
DEBUG <return>
D40:00 <return>
Information about your computer ports would be displayed if any port is absent or not responding the status of that port will be shown as 00.
Now enter Q to return.
Q <return>
Once DEBUG has been called, the somewhat cryptic "DEBUG prompt", a hyphen (-), is displayed. At the prompt, the following "DEBUG commands" are valid:
Command |
Parameters |
Action |
? |
|
This list of DEBUG commands. |
A |
[address] |
Assemble |
C |
range address |
Compare |
D |
[start address [end address | L range]] |
Displays a segment of memory. By default start address is offset 100 of the first free segment of memory, or offset 100 of the segment containing a file loaded by DEBUG. The default end address is 017F ( a range of 128 bytes). |
E |
address [list] |
Enter |
F |
range list |
Fill |
G |
[=address] [addresses] |
Go |
H |
value1 value2 |
Hex |
I |
Port |
Input |
L |
- |
Loads a previously "named" (by N command) file into memory where it can be viewed /edited. |
L |
Number |
Used with commands accepting a "range" argument to denote a number of bytes. Typically used in arguments as: start address L number. If number should take end address past the end of the segment, then number is truncated so the end address is the last byte of the segment. |
M |
range address |
Move |
N |
[path] filename [arglist] |
"Names" a file for DEBUG. A file must be "named" before it can be loaded for viewing/editing. |
O |
port byte |
Output |
P |
[=address] [number] |
Proceed |
Q |
|
Exit DEBUG. |
R |
[register] |
Register |
S |
range list |
Search |
T |
[=address] [value] |
Trace |
U |
[range] |
Unassembled |
W |
[address] [drive] [first sector] [number] |
Write |
XA |
[#pages] |
Allocate expanded memory |
XD |
[handle] |
de-allocate expanded memory |
XM |
[Lpage] [Ppage] [handle] |
Map expanded memory pages |
XS |
|
Display expanded memory status |
DEL (or ERASE)
Deletes named files. DEL and ERASE are synonymous.
Syntax:
To delete a file:
DEL [path] filename [/P]
Filename Name of file to delete.
/P Forces confirmation before deleting each file.
To delete all files in a directory with confirmation:
DEL path or
DEL path \*.*
To delete all files in a directory without confirmation:
DEL path \?*.*
DEL only accepts one parameter specifying what is to be deleted. However this parameter can be written using wildcards so that multiple files are deleted. If more than one parameter is detected, the command aborts and an error message is displayed.
DEL will be interpreted with a long file name with spaces as multiple parameters, causing an error. Enclosing the long file name with spaces in inverted commas solves the problem. Let us see an example:
D:\>del note 2.txt
Too many parameters - 2.txt
D:\>del "note 2.txt"
D:\>_
DEL does not delete files that have read-only, hidden, and/or system attributes set. To delete such files, one can use DELTREE or modify the necessary attributes with ATTRIB command.
DELTREE
Deletes Files and Directories, and all the Subdirectories and files in it.
Syntax:
To delete a directory and all the subdirectories and files contained therein:
DELTREE [/Y] directory
directory The directory to be deleted.
/Y Suppresses prompts for confirmation before
deletion.
To delete all the files and subdirectories but leave the directory itself:
DELTREE [/Y] directory\*.*
To delete a file:
DELTREE [/Y] filename
The DELTREE command deletes all files contained in a directory or subdirectory, regardless of whether files are marked as hidden, system, or read-only.
The DELTREE command supports wildcards, but they should be used with some caution. If you specify a wildcard that matches both directory names and filenames, both the directories and files will be deleted.
Before specifying wildcards with the DELTREE command, use the DIR /A command to view the files and directories you will delete. It is also safest to specify the full path to avoid any surprises from ambiguous specification. Let us see some examples.
To delete the NOTES directory on drive C, including all files and subdirectories of the NOTES directory:
DELTREE c:\notes
To delete all the files and subdirectories in the NOTES directory leaving an empty directory NOTES for future use, and avoiding the prompt for confirmation:
DELTREE /Y c:\notes\*.*
To delete the read-only file recover.doc in the c:\data directory without resetting the attributes:
DELTREE /Y c:\data\recover.doc
DOSKEY
DOSKEY is a TSR designed to assist working from the command line by making it easier to edit the command line, by remembering previous commands, and being able to record macros.
Syntax:
To load DOSKEY:
DOSKEY [/Switches]
Switches |
what it does |
/B:xxx |
Sets the size of the buffer for macros and commands. The minimum value of xxx is 256 and the default is 512 (bytes). If DOSKEY is already running, it must be reloaded (with /R) when changing the buffer size. |
/E:On|Off |
Enables|Disables the display of commands when a macro plays. E(Echo) is On by default. |
/F:filename |
Retrieves filename - a text file containing a list of macros in the form Macroname=Text |
/H |
Displays all commands stored in memory. (This list will not be redirected to a file). |
/I|O |
Specifies whether text is entered in Insert or Overstrike mode by default. In either case the alternative mode can be selected by using <Insert> but the default is reset as soon as <Enter> is used. The default mode is Overstrike. |
/K:xx |
Sets the size of the keyboard type-ahead buffer. The default is 15 (characters). If DOSKEY is already running, it must be reloaded (with /R) when changing the buffer size. |
/L |
Sets the maximum size of the line edit buffer. The default is 128 (characters). |
/M |
Displays a list of all DOSKEY macros currently in the buffer. This list can be redirected to a text file using standard Dos redirection (>) |
/R |
Installs a new instance of DOSKEY. If DOSKEY is already running, the buffer is cleared of both macros and the Command Line history. Note that installing a new instance of DOSKEY does not remove the previous instance. Thus each use of /R takes another 5K of conventional/upper memory. |
Macroname |
The name of the macro. This is a string of one or more characters possibly modified by the Ctrl and/or Alt keys. |
Text |
The text string to be assigned to Macroname. This will typically be one or more DOS commands along with appropriate parameters and/or switches. |
To create a DOSKEY macro:
DOSKEY Macroname=Text
To run a macro:
Macroname
Switches |
what it does |
/B:xxx |
Sets the size of the buffer for macros and commands. The minimum value of xxx is 256 and the default is 512 (bytes). If DOSKEY is already running, it must be reloaded (with /R) when changing the buffer size. |
/E:On|Off |
Enables|Disables the display of commands when a macro plays. E(Echo) is On by default. |
/F:filename |
Retrieves filename - a text file containing a list of macros in the form Macroname=Text |
/H |
Displays all commands stored in memory. (This list will not be redirected to a file). |
/I|O |
Specifies whether text is entered in Insert or Overstrike mode by default. In either case the alternative mode can be selected by using <Insert> but the default is reset as soon as <Enter> is used. The default mode is Overstrike. |
/K:xx |
Sets the size of the keyboard type-ahead buffer. The default is 15 (characters). If DOSKEY is already running, it must be reloaded (with /R) when changing the buffer size. |
/L |
Sets the maximum size of the line edit buffer. The default is 128 (characters). |
/M |
Displays a list of all DOSKEY macros currently in the buffer. This list can be redirected to a text file using standard Dos redirection (>) |
/R |
Installs a new instance of DOSKEY. If DOSKEY is already running, the buffer is cleared of both macros and the Command Line history. Note that installing a new instance of DOSKEY does not remove the previous instance. Thus each use of /R takes another 5K of conventional/upper memory. |
Macroname |
The name of the macro. This is a string of one or more characters possibly modified by the Ctrl and/or Alt keys. |
Text |
The text string to be assigned to Macroname. This will typically be one or more DOS commands along with appropriate parameters and/or switches. |
To create a DOSKEY macro:
DOSKEY Macroname=Text
To run a macro:
Macroname
DOSKEY Commands |
What it does |
Left/Right cursor |
Moves the cursor back/forward one character. |
Ctrl + Left/Right cursor |
Moves the cursor back/forward one word. |
Home/End |
Moves the cursor to beginning/end of line. |
Up/Down cursor |
To scroll up (and back) through the list of stored commands. Each press of the "up" key recalls the previous command and displays it on the command line. |
Page Up/Down |
Recalls the oldest/most recent command in the buffer |
F1 |
Copies the next character from the Template to the Command Line |
F2 + key |
Copies text from the Template up to (but not including) key. |
F3 |
Copies the Template from the present character position to the Command Line. |
F4 + key |
Deletes the characters from the present character position up to (but not including) key. |
F5 |
Copies the current command to the Template and clears the Command Line. |
F6 |
Places an end-of-file character (^Z) at the current position of the Command Line. |
F7 |
Displays a numbered list of the command history. |
Alt-F7 |
Deletes all commands stored in the buffer. |
Chars + F8 |
Entering one or more characters Chars followed by F8 will display the most recent command beginning with Chars. Pressing F8 again will display the next most recent command beginning with Chars, and so on. |
F9 + Command# |
Displays the designated command on the command line. |
Alt-F10 |
Deletes all macro definitions. |
To delete a macro:
DOSKEY Macroname=
DOSKEY Special Characters
The following special characters can be used in macros to control command operations:
Characters |
What is does |
$G |
Redirects output – equivalent to the redirection symbol > |
$G$G |
Appends output to the end of a file - equivalent to the append symbol >> |
$L |
Redirects input - equivalent to the symbol < |
$B |
Sends macro output to a command - equivalent to the pipe symbol | |
$T |
Separates commands when creating macros or typing commands on the DOSKEY command line |
$$ |
Use for the $ sign |
$1 to $9 |
Represents any command-line parameters that can be specified when the macro is run. Comparable with the %1 to %9 characters in batch programs |
$* |
Represents command-line information that can be specified when macroname is written. $* is similar to the replaceable parameters $n except that everything typed on the command line after macroname is substituted for the $* in the macro. |
DIR
Displays the list of Files and Subdirectories in a Directory.
Syntax:
DIR [drive:] [path] [filename] [/Switches]
Switch |
What Is does |
none |
By default, DIR displays:
- a header comprising the disk's volume label and serial number;
- a list of all files and subdirectories in the current directory in the order they are listed in the FAT except those marked 'hidden' and/or 'system'. Along with each file/directory is its size, date/time of last modification, and long file name;
- a footer comprising the total number of files listed, their cumulative size, and the free space (in bytes) remaining on the disk.
|
/A [attributes] |
Displays files with and without specified attributes. Multiple attributes can be specified with no spaces between them.
attributes (Using the "-" as a prefix specifies "not")
D Directories
R Read-only files
H Hidden files
A Files modified since last back-up
S System files |
/O
[sortorder] |
List files in sorted order.
If order of sorting is not specified, directories are listed alphabetically followed by files, also listed alphabetically. Any combination of sorting order keys can be specified and files will be sorted in the order of the keys.
sortorder (Using "-" as a prefix reverses the order)
N By name (alphabetic)
S By size (smallest first)
E By extension (alphabetic)
D By date & time (earliest first)
G Group directories first
A By Last Access Date (earliest first) |
/S |
Displays Files in the specified Directory and all its Subdirectories |
/W |
Wide list format. File and Directory names are listed in 5 columns |
/B |
Bare format. Files and Directories are listed in a single column without header, summary, or any details. |
/L |
Output is in lowercase. |
/P |
Pauses with each screen, full of information. Press any key to see the next screen. |
/V |
Forces to Verbose mode. This displays attributes, date last accessed, and disk space allocated for each file, in addition to the standard information. |
/Z |
Long file names are not displayed in the file listing. |
/4 |
Displays the date as four digits rather than two. |
The DIR command only accepts one path as a parameter. Long file and Directory names that include a space must be enclosed in inverted commas. You can also use wildcards such as * and ? to display a listing of a subset of files and subdirectories.
DIR can be used with the standard period (.) shortcuts to show higher level directories. If more periods are used than are required to show the root directory, the directories and files.
When using redirection to send the output of DIR command to a file or another command, it is often useful to use /A:-D to list only files, and /B to avoid extraneous information such as files sizes, headers and summary information. Also when the output of a DIR command is redirected via a pipe, a temporary file is created which is automatically deleted once the operation is completed.
By default, this temporary file is located in the directory specified by the "TEMP" environmental variable but, if this is not specified or cannot be found, it will be created in the current directory of the current drive. If the DIR command also refers to the current directory, any such temporary files will be picked up and included in the listing.
DISKCOPY
DISKCOPY is used to duplicate floppy disks. Any data on the destination disk is overwritten.
Syntax:
DISKCOPY drive1: [drive2:] [/1] [/V] [/M]
drive1 Drive containing disk to be copied from and to, if the computer has only one floppy drive.
drive2 Drive containing disk to be copied to if different from
drive1.
/1 Copies only the first side of the disk.
/V Verifies that the information is copied correctly.
/M Force multi-pass copy using memory only.
DISKCOPY is designed to duplicate standard floppy disks by making a byte-by-byte copy of the source disk to the destination disk. DISKCOPY do not work with hard drives, CDs, network drives, or Zip, Jazz, etc. type drives. Also it should be kept in mind Source and destination disks must be of the same type, size, and capacity. If they are not, an error message is displayed:
EDIT
It is a simple full-screen DOSased ASCII text editor.
Syntax
EDIT [/B] [/H] [/R] [/S] [/nnn] [filename(s)]
/B Forces monochrome mode.
/H Displays the maximum number of lines possible for your
hardware.
/R Load file(s) in read-only mode.
/S Forces the use of short filenames.
nnn Load binary file(s), wrapping lines to nnn characters wide.
filename(s) Specifies initial files(s) to load. Wildcards can also be used.
To see the list of shortcut keys you can see the "Help" menu of editor.
EXIT
In case of DOS of windows environment, EXIT command is used to quit the DOS shell else if talking generally, Quits the MS-DOS command interpreter (COMMAND.COM) and returns to the program that started the command interpreter, if one exists.
Syntax
EXIT
FC
Compares two files or sets of files and displays the differences between them.
Syntax:
FC [/Switches] file1 file2
Switch |
What It does |
/B |
Performs a binary comparison.
The two files are compared byte by byte and there is no attempt to resynchronize the files after finding a mismatch. This is the default mode for comparing files when file1 has an extension of .EXE, .COM, .SYS, .OBJ, .LIB and .BIN or similar to it. |
/L |
Compares files as ASCII.
The two files are compared line by line and FC attempts to resynchronize the files after finding a mismatch. This is the default mode for comparing files when file1 does not have an extension of .EXE, .COM, .SYS, .OBJ, .LIB and .BIN or similar to it. |
/LBn |
Sets the number of lines for the internal line buffer.
If the files being compared have more than this number of consecutive differing lines, FC cancels the comparison. Default value of n is 100 |
/nn |
The number of consecutive lines that must match before the files are declared resynchronized. If the number of matching lines in the files is less than this number, the matching lines are displayed as differences. Default value of nn: 2. |
/N |
Displays the line numbers on an ASCII comparison. |
/A |
Abbreviates the output of an ASCII comparison. Only the first and last line for each set of differences is displayed as opposed to the default of every different line. |
/C |
Disregards the case of letters. |
/T |
Does not expand tabs to spaces.
By default, tabs are treated as spaces with 1 tab = 8 spaces. |
/W |
Compresses tabs and multiple spaces to a single space for the comparison. |
If file1 includes a wildcard, all applicable files are compared to file2. If file2 also includes a wildcard, it is compared with the corresponding file1. In most cases, binary files are compared to see if they are the same or not. To simply see if two binary files are identical, it is often quickest to compare them as ASCII files using the /LB1 switch to cut the output to a minimum.
Let us see an example of the significant differences in processing times. By trying the following examples you will be able to understand how to use FC in Time saving and batter way:
FC c:\windows\command\xcopy.exe c:\windows\command\attrib.exe
FC c:\windows\command\xcopy.exe c:\windows\command\attrib.exe /L
FC c:\windows\command\xcopy.exe c:\windows\command\attrib.exe /L /LB1
FDISK
FDISK is a menu driven utility used to configure and/or display information about the partitions on a hard disk. You Should know What you are doing in FDISK environment and you should be sure for doing that otherwise it may delete or change your partitions’ information and you may suffer the loss of partitions(s) i.e. data.
Before a hard disk can be recognized by DOS, a Master Boot Record (MBR) must be established. FDISK is the MS-DOS utility used to create an MBR by defining the size and nature of a hard drive's partitions. The MBR defines areas of the disk to be:
- A Primary Partition and/or
- An Extended Partition
An Extended Partition has to be designated as containing one or more Logical DOS Drives. If you remove partitions, you will destroy everything on them, or, at the least, make it very difficult to recover any data. We’ll learn more about Fdisk in the Recovery programming section of this book.
FIND
The FIND command is used to search for a text string in a file or files. After searching the specified files, FIND displays any lines of text that contain the string.
Syntax:
FIND [/V] [/C] [/N] [/I] "string" "filename1" "filename2" "filename ..."
Switch |
What It Does |
/V |
Displays all lines NOT containing the specified string. |
/C |
Displays only a count of lines containing the string. If used with /V, FIND displays a count of the lines that do not contain the specified string. |
/N |
Displays line numbers with the lines. If /C and /N are used together, /N is ignored. |
/I |
Ignores the case of characters in string. By default FIND is case sensitive and searches for an exact character match. |
string |
The text string to be found. String must be in inverted commas. |
filename |
The file(s) to be searched. If filename does not contain spaces, it does not need to be enclosed in inverted commas. |
If filename is not specified, FIND searches the text input from the standard source which is usually the keyboard, a pipe, or a redirected file. Wildcards are not accepted in filename. Also as inverted commas are used to delimit string, they cannot be used within string as part of the search pattern.
To include inverted commas within string, it is necessary to use the "special character" of double inverted commas ("") which FIND interprets as inverted commas in the search string. Let us see some examples:
To display all lines from the file "NOTES.TXT" that contains the string "homework":
FIND "homework" notes.txt
If the string contains inverted commas, these must be doubled:
FIND "The result of ""B.E. Final year"" has not been displayed." Result.doc
FORMAT
Formats a disk for use with MS-DOS. Always remember that the data stored in the disk will be erased after the format. Be careful and be sure before using the format command and always remember to see which drive letter you are entering in FORMAT command.
Syntax:
FORMAT drive: [/Switches]
Switch |
What It does |
/V[:label] |
Specifies a volume label. If the /V switch is omitted, or label is not specified, a prompt for a volume label is displayed after formatting is completed. If no volume label is required, the prompt can be avoided by specifying: /V:""
If a label is specified and more than one disk is formatted in a session, all of the disks will be given the same volume label. |
/Q |
Forces the Quick format of a previously formatted disk. The file allocation table (FAT) and root directory of the disk is deleted but it is not scanned for bad areas. |
/S |
Copies system files to the formatted disk to make it a boot disk. |
/B |
Allocates space on the formatted disk for system files. |
/F:size |
Formats a disk to a capacity other than that for which the drive was designed. Size can be: 360, 720, 1.2, 1.44, and 2.88. |
/T:tracks |
Specifies the number of tracks per disk side. |
/N:sectors |
Specifies the number of sectors per track. |
/1 |
Formats a single side of a floppy disk. |
/4 |
Formats a 5.25-inch 360K floppy disk in a high-density drive. |
/8 |
Formats eight sectors per track |
/C |
Tests clusters that are currently marked "bad." By default, if a disk contains clusters that have been marked as "bad", FORMAT does not retest the clusters; it simply leaves them marked "bad". |
By default, and unless the /Q switch is used; each sector on the disk is checked during the formatting process to ensure that the sector can properly store data.
If a bad sector is located, it is marked and is not used. When formatting is complete, a message is displayed showing the total disk space, any space marked as defective, the space used and the space available for files. FORMAT cannot be used on a virtual drive created using the SUBST command.
A fast way to reformat a floppy is:
ren /? | format /q/v:"" > nul
The ren /? part feeds, along with a load of redundant material, an "enter", followed by a "n, enter" in response to FORMAT's prompts. The >nul prevents the display of the somewhat messy mixed up output of the two commands.
LABEL
The LABEL command is used to create, change, or delete the volume label of a disk. The volume label of a disk is displayed as part of the directory listing along with the volume serial number, if exists.
Syntax:
LABEL [drive:] [label]
Drive: The location of the disk to be named.
Label The new volume label.
None Displays current disk label, if they exist. Prompts to enter a new label or delete the existing one
MD (or MKDIR)
Creates a directory. MD and MKDIR are synonymous do the same tasks.
Syntax:
MD [path] directoryname
MORE
The MORE command reads standard input from a pipe or redirected file and displays one screen of information at a time. This command is commonly used to view long files, directory output, etc.
Syntax:
MORE [path] filename
MORE < [path] filename
command | MORE [path] [filename]
command a command whose output is to be displayed.
Filename file(s) to display one screen at a time
MORE filename and MORE < filename are synonymous and equivalent to TYPE filename | MORE. In all these cases filename is displayed a screenful at a time. Pressing "Enter" displays the next screen. The display can be terminated at any time by pressing Ctrl-C. MORE automatically wraps text to fit the screen.
Let us consider an example of a big text file named BIGFILE.TXT. Now the following three commands will do the same task:
TYPE bigfile.txt | MORE
MORE bigfile.txt
MORE < bigfile.txt
MOVE
Moves files and directories from one location to another on the same or different drives.
Syntax:
MOVE [/Y | /-Y] [path] filename destination
/Y Suppresses prompting to confirm creation of a directory or overwriting of the destination. This is the default when MOVE is used in a batch file.
/-Y Forces a prompt to confirm creation of a directory or overwriting of the destination. This is the default when MOVE is used from the command line.
If more than one file is listed to be moved, destination path must be a directory and the files will retain their original names.
RD (or RMDIR)
Removes (deletes) an empty directory. RD and RMDIR are synonymous and do the same tasks.
Syntax:
RD [path] directoryname
If there is a backslash ( \ ) before the first directory name in path, that directory is considered a subdirectory of the root directory on the current drive. If there is no backslash before the first directory name in path, the directory is considered a subdirectory of the current directory.
Also RD will only delete an empty directory. If RD is used on a directory containing files and/or subdirectories, Error message is displayed by the computer.
SCANDISK
Runs the SCANDISK disk-repair program.
Syntax
To check and repair the current drive:
SCANDISK
You should not scan the disk with CHKDSK or SCANDISK or any other disk scanning program if your disk is crashed or there is any logical error in your boot sectors like MBR, DBR, FAT or root directories are corrupted. It may make you data information distorted and can make it difficult to recover. Not only this you may not recover data completely |
Generally the DOS version of Scandisk does not run while Windows is running. Rather than signaling an error, it automatically transfers control to the Windows version of Scandisk
TYPE
The TYPE command is used to display the contents of an ASCII text file on screen.
Syntax:
TYPE filename
To display text files one screen at a time, pipe the output from a TYPE command to MORE. Let us see some examples:
To display the contents of ROMI.TXT:
TYPE romi.txt
If the file is too long to fit on a single screen:
TYPE romi.txt | MORE
XCOPY
This command is one of the most important commands when you want to make the backup of your important data or even you want to make the image of entire drive to Copy files and directory trees.
XCOPY is similar to the COPY command except that it has many more switches that allow considerable control over exactly what is copied when using wildcards.
Syntax:
XCOPY source [destination] [/Switches]
source The file(s) and Directories to be copied. Wildcards (* or ?) may be used.
destination The path and/or name(s) of new files. If destination is omitted, the files are copied to the current directory. If destination refers to a directory that does not exist, the directory is created. By default, XCOPY will confine its operation to files in the source directory.
Switch |
What it does |
/E |
Copies the complete subdirectory structure of source and all files therein. |
/S |
Copies the complete subdirectory structure of source and all files therein but does not copy empty subdirectories. |
/T |
Copies the subdirectory structure of source but does not copy any files and does not copy empty subdirectories. To include empty subdirectories, use with the /E switch. |
/A |
Only copies files with the archive attribute set. |
/M |
Only copies files with the archive attribute set, turning off the archive attribute of the source files. |
/H |
Includes files with hidden and system attributes set. |
/K |
Copies files without resetting the read-only attribute, if set. |
/R |
Overwrites read-only files. |
/U |
Only copies files in source that already exist in destination. Can be used with /D to update files with more recent versions. |
/D:date |
Only copies files with a 'last modified date' the same as, or later than, date. If date is not specified, all files are copied except for same-named files in the destination directory that have a more recent 'last modified date' than the one in source. |
/I |
Forces destination to be treated as a directory. The file/directory prompt is suppressed. |
/Y |
Overwrites existing files without prompting. |
/-Y |
Prompts before overwriting existing files. |
/W |
Displays a prompt before starting to copy files. |
/P |
Prompts for confirmation before creating each destination file. |
/F |
Displays full source and destination file names while copying. |
/Q |
Does not display file names or any other messages while copying. |
/C |
Continues copying even if errors occur. |
/L |
Displays files to be copied but does not actually copy them. |
/N |
Copy using the generated short names. This is necessary when copying from a VFAT volume to a FAT volume. |
/V |
Verifies that new files are readable. |
By default XCOPY will not copy files which have system or hidden attributes set and also copies of read-only files do not have the read-only attribute set, and all copied files have their archive attribute set. By default, XCOPY prompts before overwriting files in destination with files in source of the same name.
XCOPY also prompts for instructions if there is ambiguity whether destination is a directory or file. An ambiguity is seen when destination does not refer to an existing directory or end in a “\ ". For example a destination of name.ext could be either a file or a directory. Let us learn it better by the following examples.
To copy all files and subdirectories from the notes directory to the disk in drive a:
xcopy c:\notes a: /s
or
xcopy c:\notes\*.* a: /s
To copy all files and subdirectories from the notes directory created or modified since 9 dec 2002 to the disk in drive a:
xcopy c:\notes a: /s /d:9/12/02
Making the “Drive Image”
If you want to make the backup of your entire drive to another or you want to make image of your data of drive “including Operating System and other installed software” to another hard disk, just try this:
C:\> Xcopy * D: \I\E\C\H
Here D: is supposed to be the Active partition of another hard disk. This will copy the whole data of the source drive (Including installed Operating System, Software, Document etc.) as image to the Destination Drive.
And after this if you boot your computer with the destination drive, it will work same as the source drive was working and it will show all the data that you were having in the source drive.
Specification Shortcuts, Wildcards and Redirection
Shortcuts
A number of DOS commands recognize certain shortcuts when navigating between directories. The best known of these are:
Shortcut |
Why to use it |
. |
to refer to the current directory |
.. |
to refer to the parent directory |
\ |
to refer to the root directory of the current drive. |
drive: |
to refer to the current directory on drive |
Let us try to understand it with the help of examples. If the current directory on the c: drive is c:\windows\java\notes, then dir c: at the a:\> prompt will list the files in c:\windows\java\notes
- If the current drive and directory is c:\data\docs\letters, then:
- If the current drive and directory is c:\, then:
Wildcards
Many DOS commands like, ATTRIB, COPY, DEL, DELTREE, etc., accept the use of the "wildcards" (* and ?). Generally terms, * refers to multiple characters and ? refers to a single character in a file or directory name.
This is the reason we can not use these characters in the name of any file. These Special characters are / \ : * ? < > “ | which should not be tried to insert in a file name. Following table shows the use of wildcards:
Wildcard |
What it does |
*.* |
All files with all extensions. |
*data*.* |
All files with "data" anywhere in its name. |
*array.* |
All files with names ending with "array" |
note?.cpp |
All files named "note" plus one character and with .CPP extensions. This file may be note1.cpp, but not note.cpp. |
?t*.* |
All files with an "t" as second letter in their names |
It should be noted that not all commands handle wildcards in exactly the same way. For example DIR * and DIR *.* are considered synonymous but DEL * would delete only files without an extension.
A space enclosed by inverted commas (" ") is accepted as a valid file specification by EDIT and DEL yet in rather different ways.
EDIT will open a file using the name of the current directory. Thus if the current directory is D:\windows\java\notes, EDIT " " will create a file in that directory called "notes".
DEL recognizes " " as *.* and will prompt for confirmation before deleting all files in the directory. As with EDIT, the number of spaces between the inverted commas does not seem significant but if there are no spaces an error message is displayed saying that a required parameter missing.
Unlike EDIT, a path can be included and, if it is, no spaces between inverted commas are required. i.e. to delete all files in the current directory:
DEL ./"" works, but DEL "" gives an error message.
COPY also sees " " as *.* and, like DEL, accepts a path with it. Unlike DEL, there must always be a space between the inverted commas, even when a path is included
Redirection
A number of DOS commands send output to the screen and/or require input from the user. Redirection is a mechanism whereby the output of a command can be fed either to some other device for example, a printer or file, or to another program or command.
There are four redirection functions:
> |
Redirect output |
>> |
Append |
< |
Redirect input |
| |
Pipe |
>
Redirects a command's output from the "standard output device" (usually the monitor) to another device (e.g. printer) or a file.
Syntax:
To redirect output to a device:
Command > Device
To redirect output to a file:
Command > Filename
Acceptable Device names are, CON (Monitor), PRN (LPT1 - assumed to be the printer), LPT1 - 3 (Parallel Ports - usually connected to a printer), COM 1 - 4 (Serial Ports) and NUL (an electronic void).
If anything other than a recognized device is specified, it is assumed to be the name of a file. If a file already exists with the specified Filename, it is overwritten without any Warnings. Let us see some Examples to better understand it.
Probably the most common uses of this redirection function is to send directory listings to the printer or to save them as a file. To print out a sorted directory listing of all files in the Windows directory:
DIR c:\windows /o/a > PRN
To create a file containing the directory listing of the same directory:
DIR c:\windows /o/a > d:\windows.txt
>>
Appends the output from a command to the specified file.
Syntax:
Command >> Filename
If Filename does not exist, it is created. If Filename does exist, the output from the command is added to it, unlike the > function where the original contents are overwritten. Let us better understand it with example.
To add the directory listing of the files in the c:\windows\system directory to that created before:
DIR c:\windows\system /o/a >> d:\windows.txt
<
Directs input to a command from a source other than the default. The default source usually being the keyboard.
Syntax:
Command < Datasource
It is used generally in batch programming. Let us understand it with the example. The following procedure of DEBUG command is used to make the backup of MBR where MBR.BIN is the name of backup file created after this execution.
debug mbr.bin
A
MOV DX, 6000
MOV ES, DX
XOR BX, BX
MOV DX, 0080
MOV CX, 0001
MOV AX, 0201
INT 13
INT 20
<Enter>(type nothing)
G
R CX
200
W 6000:0000
Q
To this with help of batch file we make two batch files, one containing the command instruction to start DEBUG command and other to store other instructions which will be fed to the DEBUG command as input. This File will be the datasource for the first file. Let us see how:
C:\ mbr.bat
Now let us see what this MBR.BAT has in it.
MBR.BAT |
DEBUG mbr.bin < ttsource.bat |
And obviously the second file named TTSOURCE.BAT will work as datasource for this and will be having following instructions in it:
TTSOURCE.BAT |
A |
MOV DX, 6000 |
MOV ES, DX |
XOR BX, BX |
MOV DX, 0080 |
MOV CX, 0001 |
MOV AX, 0201 |
INT 13 |
INT 20 |
<enter> (Type Nothing) |
G |
R CX |
200 |
W 6000:0000 |
Q |
|
The pipe redirects the output of a program or command to a second program or command.
Syntax:
Command1 | Command2
Let us see an example of typing a long text file:
type file.txt |more
Page Modified on: 11/01/2022