Spring Sale! Save 30% on all books w/ code: PLANET24
Web Dev + WordPress + Security

DOS Fundamentals

Ahh, the fun I have at work while experimenting with the command line. I will be the first to admit that I understand very little of DOS, especially when considering the scope of its functional capacity. Nonetheless, I am taking the time to chronicle a few interesting DOScoveries here in this article, as well as in at least a couple of others (see related articles section at the end of this article).

Overview of essential DOS commands

The first thing that I should mention is that there are at least several different entities commonly referred to as “DOS”. Windows 98SE and earlier run on the MS-DOS kernel, which is directly accessible by pressing the F8 key repeatedly (after the beep) during computer startup. Windows 2000, Windows XP, and beyond do not run on the MS-DOS kernel, but do provide two MS-DOS-like programs, the command prompt Cmd.exe, and the MS-DOS emulator Command.com. For more information, you may want to explore the difference between Cmd.exe and Command.com before diving in..

File naming conventions used in DOS

All files represented via DOS consist of a root name containing one to eight characters. File names may also include an extension name containing one to three characters. A period always separates the root name from the extension. The root name may not match any device name. Here is a generalized example:

filename.ext

Should look relatively familiar. File names exceeding eight characters in length are truncated with a tilde (~). For file names, certain characters are allowed, while others are not:

Acceptable characters
A-Z a-z 0-9 $ # & @ ! ( ) - { } ' ` _ ~
..plus the period, which separates root name and extension
Unacceptable characters
| < > \ ^ + = ? / [ ] " ; , * : %
..plus control characters and blank spaces

Characters used at the command line

Here are a few important commands that are used frequently:

  • . = current directory
  • .. = up one directory level
  • *.* = all files in current directory
  • *. = all extensionless files
  • * = wildcard for any/all characters/files
  • ? = wildcard for any single character
  • \ = root directory of current drive
  • / = switch prefix
  • = switch prefix
  • > = redirects output to (overwrite) a file or device
  • >> = redirects output to (append to) a file or device
  • < = directs data from a file or device to a program or device
  • << = directs additional data from a file or device to a program or device

Environmental variables available via the DOS command prompt

Environmental variables are invaluable tools for manipulating data in DOS. Here are a few of my favorites:

System-generated upon Windows startup:

  • %DATE%
  • %TIME%
  • %SYSTEMROOT%
  • %COMPUTERNAME%

System-generated upon user login:

  • %USERNAME%
  • %USERDOMAIN%

Local machine variables for all users:

  • %PATH%
  • %HOMEPATH%
  • %HOMEDRIVE%

To configure additional local and/or user variables (or edit existing ones):

  • Windows NT » Control Panel > System > Environment tab
  • Win2K / XP » Control Panel > System > Advanced tab > Environment Variables button

Computer devices available via the DOS command prompt

Here are a few of the more useful and/or common computer devices available at the command line:

  • COM1 = Serial and/or infrared ports
  • CON = Console (display and keyboard)
  • LPT1 = Line printer (via parallel port)
  • NUL = Null device (virtual blackhole)
  • PRN = Printer (serial or parallel port)

Copy and paste command-line text via mouse

This is great — you can copy and paste command-line text using your mouse. To copy text within the DOS screen, hold the left mouse button and select the desired text, then right-click to copy the highlighted text to the clipboard. To paste the copied text within the DOS screen, simply right-click again.

Function keys available at the DOS command prompt

Here is a nice list of functional commands available during the command prompt session (via Cmd.exe):

  • F1 = Sequential, individual repeat of previously entered characters
  • F2 = Copies any number of characters from the previous command line
  • F3 = Repeats the contents of the previous command line
  • F4 = Deletes any number of characters from the previous command line
  • F5 = Return to the previous command line
  • F6 = Enters the characters ^z (CTRL+z), indicating “end of file”
  • F7 = Displays a history of commands for current session (50-line cache)
  • F8 = Sequentially displays previous command-line entries
  • F9 = Enables recall of previous commands by number (0 = first line)
  • F0 = Just seeing if you were paying attention!

Basic DOS commands

Have fun with your command line with these fabulous functions:

  • CD = CHDIR (change directory)
  • CD . = Move to the same directory
  • CD .. = Move to the parent directory
  • CD \ = Move to the root of current drive
  • CD x = Move to the “x” drive/directory
  • COPY x y = Copy file “x” to “y”
  • XCOPY x y = Copy file or directory “x” to “y”
  • DEL = ERASE (delete files)
  • DEL folder = Deletes all files within “folder”
  • DEL file = Deletes all files named “file”
  • DEL . = Deletes all files within current directory
  • DEL *.* = Deletes all files within current directory
  • RD = Removes (deletes) an empty directory
  • REN x y = Rename file “x” to “y”
  • DIR = Display contents of current directory
  • DIR /W /P *.* = Display all contents one screen at a time
  • DIR | more = Display all contents one line at a time
  • DIR /? = Provides syntax info and complete list of all DIR parameters
  • Z /? = Provides syntax info and complete list of all parameters for Z
  • TYPE file = Display the contents of the file “file”
  • TYPE file | more = Display the contents one line at a time
  • Q = Escapes sequential display of contents (i.e., the “more” parameter)
  • ECHO = Send command line input to display (by default)
  • MOVE = Moves files and renames files and directories
  • MOVE x y = Move or rename “x” to “y”
  • EDIT = Launch the MS-DOS text editor (the DOS version of notepad.exe)
  • EXIT = Exit the DOS command prompt

Related resources

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
USP Pro: Unlimited front-end forms for user-submitted posts and more.

10 responses to “DOS Fundamentals”

  1. Hi, I want to know is there any msdos command to hide a folder. thanks & regards, sajith

  2. Perishable 2007/03/01 6:35 pm Reply

    Good question, I will look into it..

    If I find anything useful, I will write an article describing the method and then post a link to it here. In the meantime, you may find this article useful, as it describes a method of "hiding" content on Windows 98.

    Stay tuned..

  3. zeratool 2007/10/03 3:15 amReply

    attrib.exe is the file

    run :
    attrib /? to view all the switches

    hope that helps.

  4. Perishable 2007/10/03 7:39 am Reply

    It sure does.. ;)

    – Thanks!

  5. Lalit Sharma 2008/05/13 3:30 amReply

    that’s good. is there any command in dos exist to send a file on network!

    plz Reply?

  6. Ashis Kumar 2008/09/18 1:38 amReply

    I fine the article is very good.Helped a lot and i like it..

  7. Jeff Starr 2008/09/21 8:40 am Reply

    Thanks for the feedback, Ashis — glad you find the article useful!

  8. Linda Lober 2009/07/11 9:54 pmReply

    Hi! This may sound crazy but I had a lightening strike and my computer has went bonkers on me. It is an old but had been reliable Compaq Windows 98. The only page that it will give me is starting in safe mode with a msdos command and I do not know what to write in the command to possible restore my computer and save all the writing files that I have done for years! Dumb on my part to not to have them on another disc.

    Interested in what to type in this space…hope you can help me restore my computer!

  9. ravindra 2010/07/28 4:11 amReply

    Its really good , its helped me in understanding basic dos commands.

  10. James F. 2022/06/20 10:32 pmReply

    One more useful function to run via the command line (or with a “Run” prompt?) could be a life-saver for some of us: XXcopy with the /NL option fixes XCOPY’s disfiguration of long filenames. One or two caveats for that:

    • Release v.2.85.7 of XXCOPY supports Win98SE but the latest Win32 version, XXCOPY 3.33.3 — does not. How can Release v.2.85.7 be obtained?
    • To precede that step the 16-bit XXCOPY16.EXE might be needed instead of just using XCOPY. How can XXCOPY16.EXE be obtained?

Leave a reply

Name and email required. Email kept private. Basic markup allowed. Please wrap any small/single-line code snippets with <code> tags. Wrap any long/multi-line snippets with <pre><code> tags. For more info, check out the Comment Policy and Privacy Policy.

Subscribe to comments on this post

Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
WP Themes In Depth: Build and sell awesome WordPress themes.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.