Skip to content
MS-DOS & FreeDOS — Complete Command-Line Guide

MS-DOS & FreeDOS — Complete Command-Line Guide

DodaTech Updated Jun 15, 2026 10 min read

MS-DOS (Microsoft Disk Operating System) and its modern open-source counterpart FreeDOS are command-line operating systems that boot directly into a text interface where you control everything by typing commands — no windows, no mouse, just pure keyboard-driven control.

What You’ll Learn & Why It Matters

In this tutorial, you’ll learn how to navigate the DOS file system, manipulate files, write batch scripts, and configure your DOS environment — skills that transfer directly to the Bash shell on Linux and the Command Prompt on Windows. DOS was the foundation of the PC revolution: every command you type in a modern terminal has roots in DOS.

Real-world use: FreeDOS runs on embedded systems, legacy industrial machinery, and retro gaming machines. Understanding DOS batch scripting also helps you understand Windows batch files (.bat and .cmd), which still run on modern Windows Server environments for automation.


What Is MS-DOS / FreeDOS, Really?

Imagine a computer that shows you a single line of text — C:\> — and waits for you to tell it what to do. That’s DOS. No desktop, no icons, no Start menu. You type a command, press Enter, and the computer responds with text output.

Why would anyone want this? Because DOS is:

  • Predictable — every command does exactly one thing
  • Controllable — you see every byte, every file, every setting
  • Learnable — there are only ~50 commands to master
  • Minimal — FreeDOS runs on a 50MB disk with 4MB of RAM

FreeDOS, released under the GNU General Public License, is fully compatible with MS-DOS 6.22 and runs the same commands, batch files, and even DOS games. It’s actively maintained and runs on modern hardware via USB or virtual machines.

The Boot Process: CONFIG.SYS and AUTOEXEC.BAT

When DOS starts, it reads two special files:

  1. CONFIG.SYS — loads device drivers and sets system parameters (like how many files can be open at once)
  2. AUTOEXEC.BAT — runs commands automatically at startup (like setting the PATH or launching a menu)

Think of these as the “settings screen” and “startup script” for your DOS system.


File System Navigation

DOS uses a hierarchical file system with drive letters (A:, C:, D:) and backslash (\) directory separators. Each disk has a root directory (C:\) that branches into subdirectories.


graph TD
    Root["C:\\ (Root)"] --> DOS["DOS"]
    Root --> DATA["DATA"]
    Root --> GAMES["GAMES"]
    
    DATA --> DOCS["DOCS"]
    DATA --> PROJ["PROJECTS"]
    
    DOCS --> README["README.TXT"]
    DOCS --> MANUAL["MANUAL.DOC"]
    
    PROJ --> BUILD["BUILD"]
    PROJ --> SRC["SRC"]
    
    GAMES --> DOOM["DOOM"]
    GAMES --> CIV["CIV"]
    
    style Root fill:#1e3a5f,color:#fff
    style DOS fill:#4a5568,color:#fff
    style GAMES fill:#2d3748,color:#fff

Essential Navigation Commands

CommandFull NameWhat It Does
DIRDirectoryLists files and folders in the current directory
CDChange DirectoryMoves to a different directory
MDMake DirectoryCreates a new directory
RDRemove DirectoryDeletes an empty directory
TREETreeShows the directory structure visually
C:\>DIR /W

 Volume in drive C is MS-DOS
 Volume Serial Number is 1A2B-3C4D
 Directory of C:\

[DOS]      [DATA]     [GAMES]    AUTOEXEC.BAT  CONFIG.SYS
README.TXT
      5 File(s)      1,432,576 bytes free

What just happened? The DIR command listed everything in the root directory. The /W flag shows a wide format (more files per line). Directories appear in brackets like [DOS].

Common Pitfall: The Path Matters

C:\>CD DATA
C:\DATA>CD DOCS
C:\DATA\DOCS>_

Each CD moves you one level deeper. To go back to the root from anywhere:

C:\DATA\DOCS>CD \
C:\>_

Notice the difference: CD \ (backslash) goes to the root, while CD .. (two dots) goes up one level. This trips up everyone at first.


File Operations: Copy, Delete, Rename, View

DOS provides simple one-word commands for all file operations.

Copying Files

C:\>COPY README.TXT DATA\DOCS\
        1 file(s) copied

The COPY command takes a source file and a destination. If the destination is a directory (ends with \), the file keeps its name.

Deleting and Renaming

C:\DATA>DEL OLD_FILE.TXT
C:\DATA>REN NOTES.TXT NOTES_OLD.TXT

Warning: DEL permanently deletes files. There’s no Recycle Bin in DOS. Once it’s gone, it’s gone — unless you use the UNDELETE command (which works only if nothing else has been written to the disk).

Viewing File Contents

C:\>TYPE CONFIG.SYS

DEVICE=C:\DOS\HIMEM.SYS
DEVICE=C:\DOS\EMM386.EXE RAM
DOS=HIGH,UMB
FILES=40
BUFFERS=30

The TYPE command displays a text file’s contents directly in the terminal. For long files, use MORE or MORE < filename.txt to scroll page by page.


Batch File Programming (BAT Files)

Batch files are the DOS equivalent of shell scripts — text files containing commands that run sequentially. This is where DOS becomes a programming environment.

Your First Batch File

REM HELLO.BAT - My first batch file
@ECHO OFF
ECHO Hello, DOS!
ECHO Today is: %DATE%
ECHO Time is: %TIME%
ECHO.
ECHO Press any key to exit...
PAUSE > NUL

Save this as HELLO.BAT and run it:

C:\>HELLO.BAT
Hello, DOS!
Today is: Mon 06-15-2026
Time is: 14:30:45.12
Press any key to exit...

Line-by-line explanation:

  • REM — a comment (ignored by the command processor)
  • @ECHO OFF — hides the commands themselves from the output
  • ECHO — prints text to the screen
  • %DATE% and %TIME% — built-in environment variables
  • PAUSE > NUL — waits for a keypress and hides the “Press any key” message

Using Variables and IF Statements

@ECHO OFF
REM CHECKFILE.BAT - Check if a file exists
SET FILENAME=%1
IF "%FILENAME%"=="" (
  ECHO Usage: CHECKFILE filename
  GOTO END
)
IF EXIST %FILENAME% (
  ECHO File %FILENAME% exists!
  DIR %FILENAME%
) ELSE (
  ECHO File %FILENAME% not found!
)
:END
ECHO Done.

Expected output when run as CHECKFILE HELLO.BAT:

File HELLO.BAT exists!
HELLO.BAT  127  06-15-26  14:30
Done.

What’s happening here? %1 captures the first command-line argument. The IF statement checks whether it was provided (""=""). IF EXIST checks the file system. GOTO :END jumps to the label.

FOR Loops

@ECHO OFF
REM LISTBAT.BAT - List all batch files
ECHO Batch files in current directory:
FOR %%F IN (*.BAT) DO ECHO Found: %%F

Expected output:

Batch files in current directory:
Found: HELLO.BAT
Found: CHECKFILE.BAT
Found: LISTBAT.BAT
🔑 Key insight: In batch files, FOR loop variables use double percent signs (%%F). Typed interactively at the command prompt, they use a single percent sign (%F). Forgetting this is the #1 batch scripting mistake.

CONFIG.SYS and AUTOEXEC.BAT Configuration

These two files define your entire DOS environment. Let’s understand each one.

A Typical CONFIG.SYS

DEVICE=C:\DOS\HIMEM.SYS     ; Extended memory manager
DEVICE=C:\DOS\EMM386.EXE RAM ; Expanded memory emulator
DEVICEHIGH=C:\DOS\ANSI.SYS  ; ANSI escape codes (colors!)
DOS=HIGH,UMB                ; Load DOS into high memory
FILES=40                   ; Max open files (default is 8)
BUFFERS=30                 ; Disk buffers (for speed)
STACKS=9,256               ; Stack frames for interrupts
LASTDRIVE=Z               ; Allow drives up to Z:

A Typical AUTOEXEC.BAT

@ECHO OFF
PROMPT $P$G              ; Show path in prompt (C:\>)
PATH=C:\DOS;C:\DATA      ; Where to look for programs
SET TEMP=C:\TEMP         ; Temporary file location
SMARTDRV.EXE             ; Disk caching for speed
DOSKEY                   ; Command history (like .bash_history)
ECHO Welcome to FreeDOS!
⚠️ Common mistake: Forgetting to add DEVICE=C:\DOS\HIMEM.SYS and DOS=HIGH,UMB. Without these, DOS runs entirely in the first 640KB of memory (conventional memory), leaving very little room for programs. With HIMEM.SYS, DOS moves into high memory (above 1MB), freeing up conventional memory for your applications.

Common Errors & Mistakes

1. Forgetting the File Extension

Mistake: Running EDIT MYFILE when the file is MYFILE.TXT.

Fix: DOS requires full filenames (8 characters max + 3-letter extension). Use DIR to see the exact filename. EDIT uses a dialog and can handle any file, but TYPE and COPY need the exact name.

2. Deleting the Wrong Files with Wildcards

Mistake: DEL *.TXT from the root directory, thinking you’re in a data folder.

Fix: Always run DIR *.TXT (or DIR *.BAT) before DEL to preview what will be deleted. Better yet, navigate to the specific directory first.

3. Infinite Loops in Batch Files

Mistake: Creating a .BAT file that calls itself recursively:

REM BAD.BAT - Don't run this!
@ECHO OFF
CALL BAD.BAT

Fix: Don’t use CALL to run the same batch file without an exit condition. Use IF with a counter or a parameter to control recursion. Or rename the called file to something different.

4. Running Out of Conventional Memory

Mistake: Installing many device drivers and getting “Out of memory” when starting a game.

Fix: Load drivers into upper memory with DEVICEHIGH instead of DEVICE. Remove unnecessary drivers from CONFIG.SYS. Use the MEM command to check memory usage:

C:\>MEM

655360 bytes total conventional memory
655360 bytes available to MS-DOS
629472 largest executable program size

5. Using CD Instead of DIR to See Files

Mistake: Typing CD when you want to see what files are in the directory.

Fix: CD changes directories (or displays the current path if used alone). DIR lists files. This is an easy typo that beginners make constantly.


Practice Questions

Question 1

What do CD \ and CD .. do, and how are they different?

Show answer`CD \` goes directly to the root directory (e.g., `C:\`) from anywhere. `CD ..` goes up one directory level (e.g., from `C:\DATA\DOCS` to `C:\DATA`). The backslash means "root" and the two dots mean "parent directory."

Question 2

What is the purpose of CONFIG.SYS?

Show answerCONFIG.SYS loads device drivers (like HIMEM.SYS for memory management and ANSI.SYS for display control) and sets system parameters like the number of open files (FILES=), disk buffers (BUFFERS=), and stack frames (STACKS=). It runs before AUTOEXEC.BAT.

Question 3

Why does FOR %%F IN (*.BAT) use double percent signs in a batch file but FOR %F at the command prompt?

Show answerBatch files require double percent signs (`%%F`) to distinguish the loop variable from command-line parameters (`%1`, `%2`). At the interactive command prompt, there are no parameters to conflict with, so a single percent sign (`%F`) works.

Question 4

What happens if you run DEL *.* from the root directory?

Show answerDOS prompts "Are you sure (Y/N)?" because `DEL *.*` deletes all files in the current directory. If you confirm Y, every file in the root is deleted. This effectively destroys the system because AUTOEXEC.BAT and CONFIG.SYS would be gone.

Question 5

How do you prevent a batch file from showing each command as it executes?

Show answerAdd `@ECHO OFF` at the top of the batch file. The `@` symbol suppresses echoing for that single line, and `ECHO OFF` turns off command echoing for the rest of the script.

Challenge

Create a batch file called BACKUP.BAT that:

  1. Creates a directory called BACKUP on the root drive
  2. Copies all .TXT files from the current directory into BACKUP
  3. Renames each copied file with the date appended (e.g., README.TXTREADME_06152026.TXT)
  4. Displays the total number of files backed up
  5. Handles the case where no .TXT files exist (shows “No files to back up” instead of an error)

Real-World Task

You’ve inherited an old industrial control system that runs FreeDOS. The system logs sensor data to SENSOR.LOG every minute. The log file grows indefinitely and fills the disk. Write a batch file that runs daily via AUTOEXEC.BAT, compresses logs using PKZIP (assume it’s installed), deletes logs older than 7 days, and emails an alert (using an email DOS tool like BLAT) when disk space drops below 10%.


Mini Project: Build a DOS Menu System

Create a batch file that displays a numbered menu system for common tasks. This is what DOS-based kiosks and old BBS (Bulletin Board System) menus looked like.

@ECHO OFF
:MENU
CLS
ECHO ═══════════════════════════════
ECHO     DOS TOOLBOX v1.0
ECHO ═══════════════════════════════
ECHO  1. View directory
ECHO  2. Check disk space
ECHO  3. Display system info
ECHO  4. Set datetime
ECHO  5. Exit
ECHO ═══════════════════════════════
CHOICE /N /C:12345 /M "Select option: "
IF ERRORLEVEL 5 GOTO END
IF ERRORLEVEL 4 GOTO SETDATE
IF ERRORLEVEL 3 GOTO SYSINFO
IF ERRORLEVEL 2 GOTO DISKSPACE
IF ERRORLEVEL 1 GOTO VIEWDIR
GOTO MENU

:VIEWDIR
DIR /W
PAUSE
GOTO MENU

:DISKSPACE
CHKDSK
PAUSE
GOTO MENU

:SYSINFO
VER
MEM
GOTO MENU

:SETDATE
DATE
TIME
GOTO MENU

:END
ECHO Goodbye!

Run it, select option 1, and you’ll see the directory listing. The CHOICE command captures keypress and sets ERRORLEVEL. Because CHOICE returns the highest number for the last option, check ERRORLEVEL from highest to lowest.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

📖 Author: DodaTech | Last updated: June 15, 2026

DodaTech tutorials are built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security tools used by millions worldwide.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro