browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

DOS: Intermediate

Posted by on May 20, 2010

Repeating or Editing a DOS Command

You can use the function keys on your keyboard for re-entering DOS commands without retyping them. Use F3 to re-display the previous commands all at once, or use F1 to re-display the command one character at a time. To execute the re-displayed command, hit <Enter>.

To delete text from a previous command, press F1 until you reach the text you want to delete. Next, press the <Del> key to remove unwanted text one character at a time. Then press F3 or F1 to display the rest of the command. Press <Enter> to execute the modified command.

To add text to a previous command, press F1 until you reach the place where you want to add text. Next, press the <Ins> key and enter the new text. Then press F3 or F1 to display the rest of the command. Press <Enter> to execute the modified command.

Revising the Disk File Structure

In DOS: Getting Started, we referred to the disk drive as a filing cabinet containing directories (like hanging folders) and subdirectories (like manila folders). Since you may have access to more than one disk drive, and each drive may have many directories and subdirectories, you may end up with a complex file structure. DOS Intermediate concentrates on how to navigate and revise this structure.

Using DOSSHELL

DOS Version 5.0 offers a new mini program called DOSSHELL, which lists the file structure (drives, directories, and subdirectories) and allows you to delete, rename, and copy files with relative ease. To access it, just type DOSSHELL and hit <Enter>.

Use tab to move forward and shift + tab to move backward in three sections of DOSSHELL: the disk drive list, the directory tree, and the list of files.

Once you reach the section you want, use your arrow keys to select a drive name, a directory name, or a file name.

At the top of the screen, you will notice pull-down menus indicated by a word which is the menu name. To access these menus, hold down the ALT key and type the first letter of the menu name. For example, to access the File menu, use ALT + F.

Then use your arrow keys to select a menu item. For example, to exit DOSSHELL, choose the File pull-down menu, then arrow key down to Exit or enter the shortcut x.

Using TREE

The TREE command displays the hierarchy of directories and subdirectories on your disk. This is particularly useful for looking at hard disks which may contain dozens of directories, many nested in other directories.

To display directories and subdirectories, type

TREE

To display the files located under each directory and subdirectory, add the /F flag:

TREE /F

Often, the tree listing will be quite long. You cause pause the TREE command output (and other lists) by pressing <Ctrl-NumLock> or <Ctrl- S>. Press again to continue the listing. You can also pause the list by using a pipe ( | ) when you enter the command. Type TREE |MORE <Enter>. See the section on "Piping Output" for more information.

Using Advanced Features of the DIR Command

In DOS Getting Started, we discussed using the DIR command to list the files in a certain drive, directory, or subdirectory. But you are not limited to listing the entire contents of a certain drive. You can specify a different drive, directory, or subdirectory no matter where you are in the file structure.

For example, if you are in the C: drive, using the directory called MEMOS, and you want to list the files in the directory LETTERS on the same drive, you type

DIR LETTERS

But if you are in the F: drive and want to list those same files in the LETTERS directory on the C: drive, you need to enter the drive letter and a backslash. Type

DIR C: \LETTERS

Further, if you are in the F: drive and want to list the files in the C: drive, LETTERS directory, and AMY-LETTERS subdirectory, you must use another backslash to separate the directory and subdirectory. Type

DIR C: \LETTERS\AMY-LETTERS

This string of commands is called a path or path-name. It tells DOS which route to take to find the desired files.

Finally, the DIR command may be used to request a listing of a specific file in a specific location. You might use this command to look for a file or to verify its location. If you are in the subdirectory AMY-LETTERS, for example, and you just want to make sure your letter BIRTHDAY.LTR is there, you type

DIR BIRTHDAY.LTR

But if you are in another location, perhaps even using another drive, you will have to indicate the drive, directory, and subdirectory for the BIRTHDAY.LTR, separated by backslashes. Type

DIR C:\LETTERS\AMY-LETTERS\BIRTHDAY.LTR

Using Wildcards

The wildcard ? (question mark) stands for any single letter in a filename, and the wildcard * (asterisk) stands for any group of letters. Used in combination with DOS commands, these wildcards can function as convenient shortcuts. For example,

  • If you want to display all files with the extension .bak in your current directory, type

    DIR *.BAK

  • If you have several files with the file name "Accounts" but different extensions (Accounts.doc, Accounts.bak, and Accounts.lst), you can copy these titles to the A: drive all at once. Type

    COPY ACCOUNTS.* A:

  • If you want to delete all the files in a specific subdirectory (such as WORD/PUBS), use the asterisk wildcard to indicate all filenames and all extensions. Type

    DEL C:\WORD\PUBS\*.*

Creating Subdirectories

You can create directories and subdirectories on a floppy disk, but you’ll find them most useful for organizing the many files on your hard disk.

To make a new directory or subdirectory, type MD followed by the name you want to give the directory. The name can have one to eight characters but no spaces, colons, commas, or periods.

For example, to create a directory named MEMOS, type

MD MEMOS

Any subdirectory will have two entries when it is created. These will be designated <DIR>. and <DIR>... The first refers to the directory itself or current directory, and the second refers to the parent directory (the one you were in when the MD command was issued). You can use "." and ".." in combination with commands as shortcuts for referring to the current and the parent directories.

If you want to further divide the directory MEMOS into two subdirectories–LATE (memos about chronic tardiness) and BREAKS (memos about coffee breaks)–you must first enter MEMOS. The director becomes the parent directory of the other two. Type

CD MEMOS <enter>
MD LATE <enter>
MD BREAKS

Removing Subdirectories

You can remove a directory or subdirectory with the RD command. First, though, you must delete all the files and any lower-level subdirectories they contain. For example, to remove all files in the directory named OBSOLETE and then the subdirectory itself, do the following:

  1. Move into the subdirectory so you can delete the files it contains:

    CD OBSOLETE

  2. Delete all the files in the subdirectory:

    DEL *.*

    (Press Y to confirm that you wish to delete all the files.)

  3. Move to the parent directory, the directory that contains the obsolete subdirectory:

    CD ..

  4. Finally, remove the obsolete directory, which is now empty:

    RD OBSOLETE

DOS Version 5.0 offers this shortcut. While you are in the parent directory of the subdirectory OBSOLETE, you may remove all the files in the subdirectory by typing

DEL OBSOLETE

Then you may immediately remove the subdirectory itself by typing

RD OBSOLETE

This movement cuts the steps down from 4 to 2.

Displaying a File on the Screen

To display the contents of a text file on screen, enter the command TYPE followed by the file name. For example,

TYPE LETTER.TXT

If the file scrolls by too fast, you can pause it by using a pipe ( | ) when you enter the command. Type

TYPE LETTER.TXT|MORE <Enter>

See the section on Piping Output for more information.

You cannot edit the displayed text with the TYPE command. However, DOS Version 5.0 offers an online editor that allows you to do so. See the section on Using the DOS Editor. Of course, you can also use a word processor to edit the file.

Using the DOS Editor

Using DOS 5.0, you can invoke the DOS Editor by typing EDIT followed by the name of the file you want to revise. For example, if you want to edit LETTER.TXT, type

EDIT LETTER.TXT

The file is shown on the screen with only rough formatting, and the lines generally stretch off the right side of the screen. It is not a good idea to re-break these lines or delete any strange-looking codes, as these may be important formatting codes.

At the top of the screen, you will notice pull-down menus indicated by a word which is the menu name. To access these menus, hold down the ALT key and type the first letter of the menu name. For example, to access the File menu, use ALT + F. Then use your arrow keys to select a menu item. For example, to print a file, choose the File menu and arrow key down to choose Print. To exit the DOS Editor, choose the File menu, then choose Exit (or enter the shortcut x).

Sending a File to the Printer

You can print the contents of a text file to your printer without going into the DOS Editor by using the PRINT command followed by the file name. For example:

PRINT LETTER.TXT

Printing the Screen

To print the contents of screen display, hold <Shift> and tap <PrtSc>. Some keyboard models have a <Print Screen> key and do not require that <Shift> be pressed. In either case, make sure the printer is turned on and ready.

Echoing Screen Output to the Printer

At times, you may want a printed record of what you do on your computer. You can use <Ctrl-PrtSc> to have text on your screen also print on your local printer. Just hit <Ctrl-PrtSc> once to start echoing text to the printer. Hit <Ctrl-PrtSc> again to stop the echoing. This procedure is useful for getting printed copies of output from DOS commands such as DIR.

Redirecting Output with DIR and TYPE

DOS normally expects your computer to display output on the screen. Redirection lets you tell DOS to send output to non-standard locations. To redirect output, use the "greater-than" symbol (>). The target for the output is indicated by a DOS device (like a printer) or a file name.

To send a list of the files in the directory C:\LETTERS to the printer, type

DIR C:\LETTERS >PRN

To send the text of a file called MYFILE.TXT to the printer, type:

TYPE MYFILE.TXT >PRN

To send the same list of files in C:\LETTERS to an actual file
named LETTER.LST that you can retrieve later, type

DIR C:\LETTERS >LETTER.LST

Piping Output to Another Command

A process related to redirection is connecting two commands so that the output of the first command serves as the input to the second. Connecting programs in this way is known as piping.

Use the vertical bar (|) to connect the commands.

Usually you use piping when you want the output of a command to be modified before being displayed or saved in a file. The special type of DOS commands that modify input are called filters.

There are three commonly used DOS filters:

  • FIND — Scans for matches with text specified in quotation marks. The following command would find any directory entries containing "1989":

    DIR | FIND "1989"

    Follow the string with /N to number the output lines, /C to get a count of the lines containing the text, or /V to exclude lines that match the text.

  • MORE — Displays a large amount of output one screenful at a time. It pauses with the message

    "–MORE–."

    Strike any key to display the next screenful. If the directory listing for MEMOS is lengthy, you could type

    DIR \MEMOS | MORE

  • SORT — Sorts lines of text. Unless otherwise specified, the sort is in ascending alphanumeric order by the first character of each line. Add the parameter /R to sort in reverse order. The /+n sorts the file by the nth character space rather than by the first. To sort a directory listing, type

    DIR C:\ | SORT

You can combine piping and redirection. To redirect the sorted output to a file, type this version of the command:

DIR C:\ | SORT >SORTFILE.TXT

Checking & Repairing the Disk

The CHKDSK command shows memory and disk space usage–how much is being used for what, and how much is available. Use the /V option to display all files and paths on the specified drive:

CHKDSK /V

The command also checks the disk for errors and reports any problems it finds. Use the /F option to fix errors found in the disk’s directory or file allocation table:

CHKDSK /F

Copying Whole Disks

Use DISKCOPY to simultaneously format a new diskette and make an exact copy of the source diskette. This command is appropriate for a two-floppy drive computer.

The target diskette should be blank or contain only expendable files. Type the command with DOS in drive A. You will be prompted to insert source and target diskettes during the procedure. It is a good idea to use a write-protect tab on your source diskette to prevent accidents.

To copy all the contents of the diskette in drive A to the diskette in drive B, enter

DISKCOPY A: B:

Note: Since this command copies the source diskette exactly, the diskette may copy into existing bad sectors on the target diskette. It is recommended that you use the COPY command instead of DISKCOPY to avoid possible problems.

Verifying Disk Copies

The VERIFY command provides extra error-checking for disk-writing operations. There is some sacrifice in speed, but many users prefer the added protection it provides. VERIFY is a good command to use each time you turn on your machine or to include in the AUTOEXEC.BAT file.

To check whether verify is turned on or off, type

VERIFY

To turn on the verify feature, type

VERIFY ON

To turn it off, type

VERIFY OFF

               

Share on Facebook

Leave a Reply