How to Defrag a Hard Drive in MS-DOS 6.22

In MS-DOS 6.22, the native command used to defragment a hard drive is DEFRAG. Over time, creating, deleting, and modifying files on a FAT filesystem causes data to scatter across non-contiguous clusters, significantly slowing down drive read and write speeds. This article covers how to use the built-in DEFRAG utility, its primary command-line switches, and best practices for optimizing disk performance in an MS-DOS environment.

The DEFRAG Command

Microsoft licensed a streamlined version of the Norton Speed Disk utility from Symantec and integrated it into MS-DOS starting with version 6.0. In MS-DOS 6.22, DEFRAG.EXE is stored natively in the C:\DOS directory.

Basic Usage

To launch the utility with its interactive, text-based graphical interface, enter the following command at the DOS prompt:

DEFRAG

Upon launch, the program prompts you to select the drive you want to optimize (e.g., drive C:). It then analyzes the disk cluster structure and recommends the best optimization method: Full Optimization (reorganizes files and clears all free space) or Unfragment Files Only (defragments files without moving all free space to the back of the drive).

You can also bypass the initial drive selection screen by specifying the target drive directly:

DEFRAG C:

Common Command-Line Switches

For automated routines, batch files, or specific reorganization preferences, DEFRAG accepts several command-line switches:

  • /F (Full Optimization): Defragments all fragmented files and consolidates all free disk space at the end of the drive.
    DEFRAG C: /F
  • /U (Unfragment Files Only): Defragments fragmented files but leaves empty clusters where they are, resulting in a faster run time.
    DEFRAG C: /U
  • /B (Restart): Reboots the computer after the defragmentation process finishes.
  • /SKIPHIGH: Prevents DEFRAG from loading into upper memory blocks (UMBs), running it strictly in conventional memory.
  • /S[:]order (Sort Order): Re-indexes and sorts directory entries during the defragmentation process. Replace order with one of the following sorting flags:
    • N / -N: By file name (alphabetical / reverse)
    • E / -E: By file extension (alphabetical / reverse)
    • D / -D: By date and time (earliest first / latest first)
    • S / -S: By file size (smallest first / largest first)

Example of fully defragmenting drive C: and sorting files alphabetically by name:

DEFRAG C: /F /SN

Important Considerations

  1. Do Not Run Under Windows: Never run the MS-DOS DEFRAG utility from inside Windows 3.1 or Windows for Workgroups 3.11. Multitasking environments that write to the disk while DEFRAG is rearranging clusters can cause severe data corruption. Always exit Windows to a pure DOS prompt before defragmenting.
  2. Run CHKDSK First: Before running DEFRAG, it is good practice to run CHKDSK /F (or SCANDISK) to ensure there are no cross-linked files or lost allocation units on the drive.