What Is a .BAT File? (.bat, .cmd)
A .bat file is a Windows batch script: a plain-text list of Command Prompt commands that run one after another when you double-click it. Batch files automate tasks such as copying files, launching programs or changing settings. The .cmd extension works almost the same. They run with your permissions, so only run trusted ones.
- Extension
- .bat, .cmd
- Full name
- Windows Batch File
- Type
- System and app file
- Developed by
- Microsoft
About BAT files
Batch files go back to MS-DOS. Windows runs them with cmd.exe, executing each line as if typed at the Command Prompt, with simple variables, IF conditions, FOR loops and GOTO labels. The .cmd extension arrived with Windows NT; for everyday scripts .bat and .cmd behave the same, with only minor differences in how some commands set error codes.
Because double-clicking runs the script immediately, a batch file can delete files, download and start programs or change system settings without further warning, and one run as administrator can change anything. Malicious BAT and CMD files are delivered in ZIP attachments and fake downloads. To see what a batch file does, open it in Notepad instead of running it.
Windows SmartScreen may warn about batch files downloaded from the internet. For more complex automation, Microsoft recommends PowerShell (.ps1), which has proper error handling and access to system management features. Batch files do not run on Mac or Linux, where shell scripts (.sh) play the same role.
What BAT files are used for
- Automating repetitive tasks like backups and file copies
- Launching programs with specific options
- Build and setup scripts for software projects
- Simple IT and network fixes
How to open a .bat file
Windows
To run it, double-click. To read or edit it safely, right-click and choose Edit (or Open with > Notepad) instead.
Mac and Linux
Batch files do not run here, but any text editor shows the commands; the equivalent is a .sh shell script.
Any platform
VS Code opens BAT and CMD files with syntax highlighting.
How to convert a .bat file
To move a batch script to PowerShell, rewrite it as a .ps1; many commands have direct equivalents, but there is no automatic converter worth trusting.
Tools exist to wrap a BAT into an .exe, but antivirus programs often flag them; share the plain BAT so others can read it.
Renaming a .txt to .bat makes its contents run as commands, so never do that with text you do not understand.
Changing the extension in the file name does not convert the file. See how to change a file extension for when renaming is safe.
Naming and renaming BAT files
- Name scripts with a verb and target (backup-photos.bat, start-dev-server.cmd) so it is obvious what double-clicking will do.
- Avoid spaces in batch file names and paths, or quote them inside the script, because cmd splits on spaces.
- Do not name a script after an existing command (copy.bat, ping.bat); it can call itself instead of the real command.
Renaming lots of .bat files? Use the free online bulk renamer for patterns and numbering, or try File Renamer AI to name each file from what is inside it.
Related file types
A .ps1 file is a PowerShell script, the file extension Microsoft uses for scripts written in its PowerShell command-line language. It contains plain text commands that automate Windows and server administration tasks. Double-clicking a .ps1 opens it in Notepad rather than running it, a deliberate safety measure.
A .sh file is a shell script: a plain-text list of commands for a Unix shell such as bash or zsh, run on Linux, macOS and Windows through WSL or Git Bash. Shell scripts automate installs, builds, backups and server tasks. They run with your permissions, so read one before running it.
A .exe file is a Windows executable: a compiled program that runs when you open it. Installers, apps and games on Windows are EXE files. Because running one gives it the same access to your computer that you have, only open EXE files from sources you trust. Macs, iPhones and Android cannot run them natively.
A .cfg file is a configuration file that stores settings for a program, game or device, usually as plain text. There is no single CFG format: some use key=value lines like INI, others lists of commands or JSON-like blocks. Notepad, TextEdit or VS Code open them; the owning program decides what each line means.
Frequently Asked Questions
Is a .bat file safe to open?
Double-clicking runs it, so only do that with scripts from trusted sources. To check one, open it in Notepad and read the commands.
How do I edit a batch file?
Right-click it and choose Edit or Open with > Notepad, change the commands and save.
What is the difference between .bat and .cmd?
Both are Windows batch scripts run by cmd.exe. Differences are minor and mostly affect error codes in a few commands.
Can I run a .bat file on a Mac?
No. Rewrite it as a shell script (.sh), or run it in a Windows virtual machine.