.bat

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.

Category
Code and data
Type
Plain text
Also seen as
.cmd
Is a .bat file safe to open? Caution. Double-clicking a .bat runs its commands at once, which can be destructive or malicious. Right-click and Edit to read it first, and only run batch files you trust.

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.

What opens 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

Open a .bat file step by step

  1. Confirm the file really is a .bat. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with Right-click, Edit (read in Notepad) or double-click or cmd (to run, caution).
  3. On Mac, use Text editor (to read only; does not run on macOS).
  4. On Linux, try Text editor (to read only; does not run on Linux).
  5. Still stuck? Convert the .bat to Not convertible, which opens more widely.

Why can't I open my .bat file?

Almost always because no installed app understands BAT. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .bat at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

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 has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

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. How sources are ranked and what is deliberately left out is set out in the methodology.