Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Just curious. "Cool" people in our company always use *.cmd while no one was able to explain the difference to me.

share|improve this question
up vote 5 down vote accepted

Here is a good discussion from Stackoverflow.

share|improve this answer
Yes, in particular the answer starting with "Here is a compilation of verified information",… – Peter Mortensen Aug 5 '09 at 12:31

There are semantic differences in the command language used for each (.bat files get a compatibility version). Some of these can be illustrated by this script from over here:

@echo off&setlocal ENABLEEXTENSIONS
call :func&&echo/I'm a cmd||echo/I'm a bat
goto :EOF

set var=1

Basically, .cmd files get the current, sexier version of the MS command language, which is why the cool kids use them.

share|improve this answer
<3 obfuscated cmd scripts :) – grawity Jun 2 '09 at 16:55
Yeesh! I stand corrected. I never knew that behaviour of CMD.EXE before. – Evan Anderson Jun 2 '09 at 16:57

According to Wikipedia:

.bat: The first extension used by Microsoft for batch files. This extension can be run in most Microsoft Operating Systems, including MS-DOS and most versions of Microsoft Windows.

.cmd: The newer .cmd extension is described by Windows NT based systems as a 'Windows NT Command Script' and is helpful, as using a .cmd extension rather than .bat extension means that earlier versions of Windows won't know how to run it, so that they don't try to and mistake the commands for COMMAND.COM style files and fail to run the new style commands due to the lack of command extensions, resulting in scripts only being partially run which could prove damaging (for example; failing to check the successful copying of a file and then deleting the original anyway).

The only known difference between .cmd and .bat file processing is that in a .cmd file the ERRORLEVEL variable changes even on a successful command that is affected by Command Extensions (when Command Extensions are enabled), whereas in .bat files the ERRORLEVEL variable changes only upon errors.

Hope this helps.

share|improve this answer

In theory .cmd is more "trueЪ" :) because .bat is a script for the old DOS while .cmd is for cmd.exe from Windows NT, the last one has a little more improved scripting. In the real life usually both are equal, like writing /bin/sh or /bin/bash in Linux (mean distros where sh is actually bash)

share|improve this answer

I first saw the .cmd format used under OS/2. If you're thinking in DOS terms, it's like a .bat file on steroids. .bat files were introduced first under DOS type OS's. Alot of the syntax is similar except when you begin to get into advanced functions. Also, a .cmd file has the potential to not work in a 16-bit environment (win98) whereas a .bat file will probably work in all environments.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.