What is a .bat file?
Windows Batch File · Code and data · Microsoft · 1980s
A BAT file is a Windows batch script: plain-text commands that Command Prompt runs when you open it. It automates routine tasks. Because double-clicking runs it immediately, treat an unexpected .bat with caution.
What is a .bat file used for?
A batch file lists Command Prompt commands to run in sequence, the Windows counterpart to a shell script. The .cmd extension is the same idea.
The important difference from a shell script is that double-clicking a .bat runs it right away, with no prompt, so an unfamiliar one is genuinely risky.
It is still plain text underneath. To read one safely, right-click and choose Edit to open it in Notepad rather than double-clicking.
Batch files are handy for setup, cleanup and launching programs, but only run ones you wrote or trust.
How to open a .bat file
The .bat format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.
Windows
- Right-click, Edit (read in Notepad)
- double-click or cmd (to run, caution)
macOS
- Text editor (to read only; does not run on macOS)
Linux
- Text editor (to read only; does not run on Linux)
Web
- Not applicable
How to convert a .bat file
You can convert a .bat file to Not convertible using a conversion tool or the export menu of an app that opens it.
.bat file signature (magic bytes)
Programs recognise a .bat file by the bytes at the start of the file, not by its name. These are the signatures for BAT.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; often starts with @echo off (no fixed signature) |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .bat file?
A BAT file is a Windows batch script: plain-text commands that Command Prompt runs when you open it. It automates routine tasks. Because double-clicking runs it immediately, treat an unexpected .bat with caution.
How do I open a BAT file without running it?
Right-click the file and choose Edit, which opens the commands as text in Notepad. Double-clicking, by contrast, runs the batch file immediately.
Is a .bat file safe?
Only if you trust it. A batch file can run any command Windows allows, so read it first and never run one that arrived unexpectedly by email or download.
Related formats
Sources
Details on this page were checked against authoritative references: